【问题标题】:Evaluate the second order differential equation in MATLAB在 MATLAB 中计算二阶微分方程
【发布时间】:2015-04-13 19:08:28
【问题描述】:

我在 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 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);

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

【问题讨论】:

  • 请详细说明
  • MATLAB documentationezplot(accByTh, [0, 5])
  • @m.s.:我试过了,但出错了。请看下面的截图-dl.dropboxusercontent.com/u/51884474/MATLAB.png你可以为a=10提供一些价值我想为给定的th绘制时间accByTh
  • 您的第一个块中的代码对我不起作用,我得到:第二个参数必须是指定微分数的变量或非负整数。
  • first block??你的意思是,你不能跑到这里p = diff(ybythd);?它在 MATLAB 2010 中运行良好。顺便说一下,最后一段代码只是为了演示问题而编写的,以后可以更改。添加它,只是为了让问题更清楚。

标签: matlab plot derivative


【解决方案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])

【讨论】:

  • 它也对我有用。但我想根据 th 推导出 accByTh 的方程。稍后,我可以提供任何th 作为t 的函数。你能把这个事实也纳入进来吗?
  • 我认为您可能需要手动操作
  • @m.s.:变量th 是时间的函数,例如th=a*cos(t)。现在,如果我区分accByTh wrt th,我会得到d(th)/d t 的一些术语。如何绘制d(accByTh)/d th wrt t?其中th 是时间函数t
  • @RaviJoshi:th=a*cos(t) 的预期结果函数如何?
  • @m.s.:将参数th 视为时间函数t。它可以是任何函数。现在计算d(accByTh)/d th。绘制 d(accByTh)/d th wrt t 并提供任何 th 作为时间的函数
猜你喜欢
  • 2022-01-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-29
相关资源
最近更新 更多