2016-10-07 32 views
2

區分內聯函數假設我寫在MATLAB如何在MATLAB

c='x^2-6'; 
f=inline(c); 

以下則F將是一個內聯函數。我可以通過輸入

f(2) 
f(5) 

然而,當我嘗試diff(f)它不返回評估在不同的值F。我如何能從f得到?

回答

2

您不能使用inline對象進行符號數學計算。使用sym對象,而不是:

c= sym('x^2-6'); % creates the 'sym' object 
subs(c,2) % calculates c(2) 
diff(c); 

還要注意的是inlinewill be removed在未來的版本

2

您需要MATLAB Symbolic Toolbox。你所描述的是所謂的象徵性分化。 (還有符號整合等)。 MATLAB的「正常」(非符號)版本被設計用來進行數值計算,而不是微積分或代數運算。

+0

我怎麼知道,如果我已經有工具箱或沒有? – mathemagician

+0

試試看看你是否收到錯誤信息。 – grendelsdad

0

這是一個符號方法,將函數和參數作爲用戶輸入並區分它。

clear; 
clc; 
v=input('Parameter :');%input for example 'x' and remember the quotes 
syms(v);%symbolic variable : x in this case 
y=input('function :');%example exp (x) ,not exp(y) or ay other variable 
f=matlabFunction(y);%converts y to a command type function f 
df = matlabFunction(diff(y)); %calculates the differentiation. 

現在,如果你做類似F(1),它會顯示2.71828和DF(1)將顯示2.71828