Differentiate an inline function

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

Azzi Abdelmalek
Azzi Abdelmalek 2012년 11월 23일
Post your code
Jose
Jose 2012년 11월 23일
f = vectorize(inline(string_from_input)); d8f = diff(f, 8); ...
Azzi Abdelmalek
Azzi Abdelmalek 2012년 11월 23일
It's not clear,what do you want to do?
Walter Roberson
Walter Roberson 2012년 11월 23일
Is it required that you use an inline function? Could you use a symbolic function instead? Considering that you are using the symbolic diff() routine?
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.
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일

0 개 추천

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개)

Matt J
Matt J 2012년 11월 23일
편집: Matt J 2012년 11월 23일

0 개 추천

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;

카테고리

도움말 센터File Exchange에서 Function Creation에 대해 자세히 알아보기

질문:

2012년 11월 23일

Community Treasure Hunt

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

Start Hunting!

Translated by