您如何在函数句柄上进行符号区分? [英] how do you do symbolic differentiation on function handle?
问题描述
请问我是否定义以下内容:
Say if i define the following:
g = @(x) x/sqrt(x^2+1)
我如何获得g的导数函数,然后可以用它在不同的点求值?
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)
但是,我无法弄清楚如何将其转换为函数句柄/在不同点进行求值.但是,我更喜欢在function_handle上进行区分.
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.
非常感谢!
Jason
推荐答案
您可以使用 matlabFunction 将符号方程式转换为函数.例如:
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);
然后Df1(0,0)会按预期返回[0 0].
Then Df1(0, 0) returns [0 0] as expected.
函数 matlabFunction 是在5.2版(R2009a)中引入的的符号数学工具箱.
这篇关于您如何在函数句柄上进行符号区分?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!