【发布时间】: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。在绘图之前,我将符号的值替换为a 和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 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 documentation:
ezplot(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