计算一个矢量的衍生物 [英] Calculate the derivative of a vector
问题描述
我有以下功能(维维安尼的曲线):
I have the following function (Viviani's curve):
Phi = @(t)[ cos(t)^2, cos(t)*sin(t), sin(t) ]
只是一个检查,它是有效的:
Just a check that it's valid:
s = linspace(0,T,1000);
plot3(cos(s).^2, cos(s).*sin(s), sin(s));
如何衍生功能披
(也许多次),从而重新presents维维安尼的曲线中的一个点 T
,其中 T
从 0
进入 2 * PI
?难道我定义的披
适用于这样的衍生品?我试过差异
,但它并没有保持披
因为我需要它。
How to derivate the function Phi
(maybe multiple times), which represents Viviani's curve in a point t
where t
goes from 0
to 2*pi
? Did I defined Phi
suitable for such a derivative? I've tried diff
, but it did not keep the Phi
as I would need it.
如果二阶导数是 Phi_d2
,我需要得到它的价值(例如 T = 0
)。
If the second derivative would be Phi_d2
, I need to get it's value (for example in t = 0
).
我怎样才能做到这一点?
How can I achieve this?
推荐答案
下面是您可以用三种方式实现。第一种使用 潜艇
,第二次使用 symfun
一>,第三个使用复杂的一步分化
Here are three ways you can accomplish this. The first uses subs
, the second uses a symfun
, and the third uses complex step differentiation:
% Using subs
syms t
Phi = [cos(t) cos(t).*sin(t) sin(t)];
Phi_d2 = diff(Phi,t)
double(subs(Phi_d2,t,0))
% Using symfun
syms t
Phi(t) = [cos(t) cos(t).*sin(t) sin(t)];
Phi_d2 = diff(Phi,t)
double(Phi_d2(0))
% Using complex step differentiation
Phi = @(t)[cos(t) cos(t).*sin(t) sin(t)];
h = 2^-28;
cdiff = @(f,x)imag(f(x(:)+1i*h))/h;
Phi_d2 = cdiff(Phi,0)
您可以找到一个函数来执行第一级和第二级复杂的一步分化在我的GitHub: CDIFF
。需要注意的是复杂的一步分化将不会为高阶导工作。这是最好的时候,人们只要一不可微函数或需要快速数值一阶导数。
You can find a function for performing first- and second-order complex step differentiation on my GitHub: cdiff
. Note that complex step differentiation won't work well for higher order derivatives. It's best when one only has a non-differentiable function or needs fast numerical first derivatives.
这篇关于计算一个矢量的衍生物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!