getting "Not enough Input arguments" for this code. Can some one help

1 view (last 30 days)
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 Comments
Madhavan Pillai
Madhavan Pillai on 23 Aug 2017
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))];
José-Luis
José-Luis on 23 Aug 2017
Edited: José-Luis on 23 Aug 2017
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.

Sign in to comment.

Accepted Answer

KSSV
KSSV on 23 Aug 2017
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 Comments
Madhavan Pillai
Madhavan Pillai on 23 Aug 2017
Thank You. And sorry for not checking the answer completly the first time. New to MATLAB... Thats why. Will be needing more help with complex problems in coming days. Once Again thank u so much for prompt response and saving my day.
KSSV
KSSV on 23 Aug 2017
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!