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

조회 수: 1 (최근 30일)
Madhavan Pillai
Madhavan Pillai 2017년 8월 23일
댓글: KSSV 2017년 8월 23일
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
Madhavan Pillai
Madhavan Pillai 2017년 8월 23일
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 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
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
Madhavan Pillai
Madhavan Pillai 2017년 8월 23일
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 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개)

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by