Substituting the parameters in second order differential equation

3 次查看(过去 30 天)
Hi,
I am deriving second order differential equation in MATLAB. I have defined a time dependent variable and then applied some derivative operations like below.
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
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))
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))
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 commands can plot p wrt time t -
syms 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(i)= 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.
-
Thanks
Ravi
  1 个评论
Jan
Jan 2015-4-16
If you do not get an answer here, most likely some important information is missing. So bumping without adding new details is not successful usually.
Please explain what "does not work" mean exactly. Do you get an error message? If so, please post it completely.

请先登录,再进行评论。

回答(2 个)

Ravi Joshi
Ravi Joshi 2015-4-16
Anybody ? is it possible in MATLAB?
- Thanks Ravi

Jan
Jan 2015-4-16
As far as I can see, t is not defined before "thAct = sin(2*pi*t)".
Inside the loop you use "t" as index, but it does not change during the loop:
pVal(t)= subs(temp,t,time(i));
Do you mean:
pVal(i)= subs(temp,t,time(i));
?
If you explain what "does not work" means, creating an answer would need less bold guessing.
  1 个评论
Ravi Joshi
Ravi Joshi 2015-4-16
Thanks Jan, It was a typing error. I modified the code. However the problem still persist. I tried to debug the problem. The expression of p seems the culprit. It has an outer diff statement. Even after substituting the values, newP has this diff statement.
Can you please look into it again?

请先登录,再进行评论。

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by