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
2016년 2월 27일
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
2016년 2월 27일
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
2016년 2월 27일
편집: sara rastakhiz
2016년 2월 27일
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 Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!