在MATLAB中评估二阶微分方程 [英] Evaluate the second order differential equation in MATLAB

查看:99
本文介绍了在MATLAB中评估二阶微分方程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在MATLAB中推导二阶微分方程.我定义了一个时间相关的变量,然后将其应用于派生运算-

I am deriving a second order differential equation in MATLAB. I have defined a time dependent variable and then applied following derivative operations-

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的值-

These operations calculates the value of p as following-

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

Now, I want to plot the variable p wrt time t. Before plotting, I substituted the value of symbols a and b

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 wrt时间t-

The variable th = sin(2*pi*t); should be substituted in order to convert the above second order differential equation into a liner equation of time t. Later on the following command can plot p wrt time 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);

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

But the above code does not work. Somebody please tell me how to substitute the parameters in second order differential equation.

推荐答案

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

The following code worked for me, however I am not 100% sure if this is exactly what you want to achieve. If it is not, please update your question accordingly.

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])

这篇关于在MATLAB中评估二阶微分方程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆