Differential of a User-defined Function (Matlab)

조회 수: 7 (최근 30일)
Richard
Richard 2011년 8월 8일
Hi,
How might I make my script perform differentiation on a user-defined function? I also want the function and its derivative (in the form of a function) to be applied throughout the script, say in the forms of f and f' respectively, which I believe requires str2func.
Example: The user is prompted for an f(x). He enters x^3. Then both x^3 and 3*x^2 are applied in the place of f and f' throughout the script.
Thanks in advance!

채택된 답변

Walter Roberson
Walter Roberson 2011년 8월 8일
It is tedious and error-prone to write your own differentiation operation. For example, what if the user entered Ei(GAMMA(hypergeom([1],[2,2],x))) -- how would you differentiate that?
If you have MuPad it is much easier to get MuPad to differentiate for you. You would not use str2func() for that. You might, though, use
fprime = matlabFunction(diff(sym('x^3')));
Note: it is not allowed to use f' as a variable name in MATLAB.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Functional Programming에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by