フィルターのクリア

Differentiate an inline function

13 ビュー (過去 30 日間)
Jose
Jose 2012 年 11 月 23 日
Hi!
I have an assignment in Matlab and I need to find a function's 8th and 9th derivate. This function is an inline function, as it is an input from the user.
I have been trying to use the function diff, but it tells me: «Function 'diff' is not supported for class 'inline'.»
Any ideas?
  6 件のコメント
Jose
Jose 2012 年 11 月 23 日
I wish, but the function is an input from the user, and I don't know any way to convert it to a symbolic one.
But if there is an alternative to the diff function, it may work.
Walter Roberson
Walter Roberson 2012 年 11 月 23 日
syms x
f = sym(string_from_input);
diff(f,x,x,x,x,x,x,x,x)

サインインしてコメントする。

採用された回答

Matt Fig
Matt Fig 2012 年 11 月 23 日
編集済み: Matt Fig 2012 年 11 月 23 日
f = inline('x^8'); % Our inline function.
D8 = diff(sym(f),8) % Find the 8th derivative
D8 == prod(1:8) % Check. ans = 1 as expected.
  1 件のコメント
Jose
Jose 2012 年 11 月 23 日
Thanks you so much!

サインインしてコメントする。

その他の回答 (1 件)

Matt J
Matt J 2012 年 11 月 23 日
編集済み: Matt J 2012 年 11 月 23 日
You cannot do symbolic differentiation on inline functions. If you don't have the Symbolic Toolbox, you will have to either consider a specific family of functions and pre-analyze their derivatives. Or, if you want to do numeric differentiation,
t=linspace(0,T,N);
f = vectorize(inline(string_from_input));
result = diff(f(t),8)./( t(2)-t(1) )^8;

カテゴリ

Help Center および File ExchangeFunction Creation についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by