在MATLAB中评估二阶微分方程

时间:2015-04-13 19:08:29

标签: matlab plot derivative

我在MATLAB中推导出二阶微分方程。我已经定义了一个时间因变量,然后应用了导数运算 -

syms a b;
th = sym('th(t)'); %th is a time dependent variable
y = diff(a^2*cos(th)+(b/12)*sin(th));
thd = diff(th); %derivative of th wrt time
ybythd = diff(y,thd); %derivative of y wrt thd
p = diff(ybythd); %derivative of ybythd wrt time

这些操作计算p的值如下 -

p = diff(diff((b*cos(th(t))*diff(th(t), t))/12 - a^2*sin(th(t))*diff(th(t), t), t), diff(th(t), t))

现在,我想绘制变量p wrt time t。在绘图之前,我替换了符号ab

的值
newP = subs(p,[a,b],[2.1,9.5])
newP = diff((19*cos(th(t))*diff(th(t), t, t))/24 - (19*sin(th(t))*diff(th(t), t)^2)/24 - (441*cos(th(t))*diff(th(t), t)^2)/100 - (441*sin(th(t))*diff(th(t), t, t))/100, diff(th(t), t))

应该替换变量th = sin(2*pi*t);,以便将上述二阶微分方程转换为时间t的线性方程。稍后,以下命令可以绘制p时间t -

thAct = sin(2*pi*t);%The function of th
time = 0.0:0.1:5.0;
for i = 1:length(time)
    temp = subs(newP,th,thAct);
    pVal(t)= subs(temp,t,time(i));
end

plot(time,pVal);

但上面的代码不起作用。有人请告诉我如何用二阶微分方程代替参数。

1 个答案:

答案 0 :(得分:1)

以下代码对我有用,但是我不能100%确定这是否是您想要实现的目标。如果不是,请相应更新您的问题。

syms a;
th = sym('th(t)');
x = a*cos(th);
v = diff(x);
acc = diff(v);
accByTh = diff(acc,t);
ezplot(subs(accByTh,th,'a*cos(t)'),[-pi,pi])