Thannks,I made the corrections and I am getting the below error. Can you please check if you are able to execute this code. Error:"Subscript indices must either be real positive integers or logicals" @yp(2) =-1/M*[Ks(z(1)-z(3)+Cs(z(2)-z(4))];
getting "Not enough Input arguments" for this code. Can some one help
조회 수: 1 (최근 30일)
이전 댓글 표시
function yp=qcar(t,z)
M=1000;
m=100;
Cs=1000;
Ks=36000;
Kt=360000;
R=150;
yp=zeros(4,1);
yp(1)=z(2);
yp(2)=-1/M*[Ks(z(1)-z(3))+Cs(z(2)-z(4))];
yp(3)=z(4);
yp(4)=-1/m*[Ks(z(1)-z(3))+Cs(z(2)-z(4))-Kt(z(3)-R)];
And in another .m file
z0=[0,0,0,0];
[t,z]=ode113(qcar,[0:0.2:10],f0);
plot(t,z);
댓글 수: 2
José-Luis
2017년 8월 23일
편집: José-Luis
2017년 8월 23일
It is much simpler for you to use the debugger and figure out that error on your own.
dbstop if error
Run your code and then look at the offending variables whenever it crashes. The error should become obvious.
Learn to use the debugger, it will save you a lot of grief and time in the future.
채택된 답변
KSSV
2017년 8월 23일
You made multiple mistakes in the function: I have rectified them check it.
z0=[0,0,0,0];
[t,z]=ode113(@qcar,[0:0.2:10],z0);
plot(t,z);
function yp=qcar(t,z)
M=1000;
m=100;
Cs=1000;
Ks=36000;
Kt=360000;
R=150;
yp=zeros(4,1);
yp(1)=z(2);
yp(2)=-1/M*[Ks*(z(1)-z(3))+Cs*(z(2)-z(4))];
yp(3)=z(4);
yp(4)=-1/m*[Ks*(z(1)-z(3))+Cs*(z(2)-z(4))-Kt*(z(3)-R)];
end
댓글 수: 4
KSSV
2017년 8월 23일
You are welcome....
Will be needing more help with complex problems in coming days I advice you to learn MATLAB which is very easy..instead of posting in the forum..use this forum for major issues when you get stuck.
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!