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...

Respuestas (1)

Star Strider
Star Strider el 27 de Feb. de 2016
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 comentarios

sara rastakhiz
sara rastakhiz el 27 de Feb. de 2016
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 el 27 de Feb. de 2016
Editada: Star Strider el 27 de Feb. de 2016
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 el 27 de Feb. de 2016
Editada: sara rastakhiz el 27 de Feb. de 2016
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 el 27 de Feb. de 2016
Did you use my code? It works, except that you will need different initial conditions to provide anything other than a zero output.

Iniciar sesión para comentar.

Categorías

Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.

Preguntada:

el 27 de Feb. de 2016

Comentada:

el 27 de Feb. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by