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

1 vue (au cours des 30 derniers jours)
Madhavan Pillai
Madhavan Pillai le 23 Août 2017
Commenté : KSSV le 23 Août 2017
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 commentaires
Madhavan Pillai
Madhavan Pillai le 23 Août 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 le 23 Août 2017
Modifié(e) : José-Luis le 23 Août 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.

Connectez-vous pour commenter.

Réponse acceptée

KSSV
KSSV le 23 Août 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 commentaires
Madhavan Pillai
Madhavan Pillai le 23 Août 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 le 23 Août 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by