ode 45 erroe undefined argument...
Show older comments
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...
Answers (1)
Star Strider
on 27 Feb 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 Comments
sara rastakhiz
on 27 Feb 2016
Star Strider
on 27 Feb 2016
Edited: Star Strider
on 27 Feb 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
on 27 Feb 2016
Edited: sara rastakhiz
on 27 Feb 2016
Star Strider
on 27 Feb 2016
Did you use my code? It works, except that you will need different initial conditions to provide anything other than a zero output.
Categories
Find more on 2-D and 3-D Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!