开发者

how do you do symbolic differentiation on function handle?

Say if i define the following:

g = @(x) x/sqrt(x^2+1)

How do i get the derivative function for g, which i can then use to evaluate at different points?

I tried the symbolic math toolkit, and tried the following:

>> syms x

>开发者_运维技巧> f = x/sqrt(x^2+1)

f =

x/(x^2 + 1)^(1/2)

>> diff(f)

ans =

1/(x^2 + 1)^(1/2) - x^2/(x^2 + 1)^(3/2)

However, i cannot figure out how to turn this into a function handle/evaluate at different points. However, i prefer doing differentiation on function_handle.

Thank you very much!

Jason


You can use matlabFunction to convert a symbolic equation to a function. For example:

syms x1 x2;
f1 = x1^2+x2^2;
Df1 = jacobian(f1, [x1 x2]);
Df1 = matlabFunction(Df1);

Then Df1(0, 0) returns [0 0] as expected.

The function matlabFunction was introduced in version 5.2 (R2009a) of the Symbolic Math Toolbox.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜