ode 45 erroe undefined argument...

i get this error: Undefined function or variable 't'. for this code: function dy=doub(t,y) dy=zeros(4,1); dy(1)=y(2); dy(2)=(-0.1737*sin(y(1))-0.0579*sin(y(1)-2*y(3))-2*sin(y(1)-y(3))*16.4042*(y(4)^2-y(2)^2)*cos(y(1)-y(3))*0.0059)/(0.2905-9.6875*cos(2*y(1)-2*y(3))); dy(3)=y(4); dy(4)=(2*sin(y(1)-y(3))*(1.9375*Y(2)^2+0.1158*cos(y(1))+9.6875*10^2*y(4)^2*cos(y(1)-y(3))))/(0.2905-9.6875*cos(2*y(1)-2*y(3))); end and i cant find the reason... help me plz i need to find out why i get this error...

回答 (1 件)

Star Strider
Star Strider 2016 年 2 月 27 日

0 投票

Actually, it says Undefined function or variable 'T'. MATLAB is case-sensitive, so ‘T’ is not the same as ‘t’. The same goes for ‘y’ and ‘Y’.
This works:
Function —
function dy=doub(t,y)
dy=zeros(4,1);
dy(1)=y(2);
dy(2)=(-0.1737*sin(y(1))-0.0579*sin(y(1)-2*y(3))-2*sin(y(1)-y(3))*16.4042*(y(4)^2-y(2)^2)*cos(y(1)-y(3))*0.0059)/(0.2905-9.6875*cos(2*y(1)-2*y(3)));
dy(3)=y(4);
dy(4)=(2*sin(y(1)-y(3))*(1.9375*y(2)^2+0.1158*cos(y(1))+9.6875*10^2*y(4)^2*cos(y(1)-y(3))))/(0.2905-9.6875*cos(2*y(1)-2*y(3)));
end
Script —
[t,y]=ode45(@doub,[0 3000],[0 0 0 0]);
plot(t,y(:,1),'-',t,y(:,2),'-o',t,y(:,3),'-.',t,y(:,4),'.');

4 件のコメント

sara rastakhiz
sara rastakhiz 2016 年 2 月 27 日
thank u really!!! for answering my questions but the thing is...i tries what u said but again i get the same error...i no longer know what to do...again thank u
Star Strider
Star Strider 2016 年 2 月 27 日
編集済み: Star Strider 2016 年 2 月 27 日
As always, my pleasure!
Other than choosing different initial conditions, this works for me.
Function file —
function dy=doub(t,y)
dy=zeros(4,1);
dy(1)=y(2);
dy(2)=(-0.1737*sin(y(1))-0.0579*sin(y(1)-2*y(3))-2*sin(y(1)-y(3))*16.4042*(y(4)^2-y(2)^2)*cos(y(1)-y(3))*0.0059)/(0.2905-9.6875*cos(2*y(1)-2*y(3)));
dy(3)=y(4);
dy(4)=(2*sin(y(1)-y(3))*(1.9375*y(2)^2+0.1158*cos(y(1))+9.6875*10^2*y(4)^2*cos(y(1)-y(3))))/(0.2905-9.6875*cos(2*y(1)-2*y(3)));
end
Script file —
[t,y]=ode45(@doub,[0 3000],[0 0 0 0]);
plot(t,y(:,1),'-',t,y(:,2),'-o',t,y(:,3),'-.',t,y(:,4),'.');
This runs without error, although it’s unlikely to be interesting to any but those who enjoy watching paint dry, given the initial conditions provided.
Different initial conditions may make it more interesting.
What do you want it to do? What do we need to do to get it sorted?
sara rastakhiz
sara rastakhiz 2016 年 2 月 27 日
編集済み: sara rastakhiz 2016 年 2 月 27 日
i know it should work but...u see i tries the same example matlab gas provided in help but i got the same error...i guess there is a problem with my software...
its a project about towed systems i am analysing the cable and for starters i have divided it to tow parts and treated it like a double pendulum and when i get answers i will try the same this time with unlimited variables...
Star Strider
Star Strider 2016 年 2 月 27 日
Did you use my code? It works, except that you will need different initial conditions to provide anything other than a zero output.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

質問済み:

2016 年 2 月 27 日

コメント済み:

2016 年 2 月 27 日

Community Treasure Hunt

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

Start Hunting!

Translated by