本文介绍了计算向量的导数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下函数(Viviani 曲线):

I have the following function (Viviani's curve):

Phi     = @(t)[ cos(t)^2, cos(t)*sin(t), sin(t) ]

只是检查它是否有效:

s = linspace(0,T,1000);
plot3(cos(s).^2, cos(s).*sin(s), sin(s));

如何推导函数Phi(可能多次),它代表了点t处的Viviani曲线,其中t来自02*pi?我是否定义了适用于这种衍生的 Phi ?我已经尝试过 diff,但它没有保留我需要的 Phi.

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?

推荐答案

您可以通过以下三种方式完成此任务.第一个使用 subs,第二个使用 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.

这篇关于计算向量的导数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-27 22:40