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 Center および File ExchangeProgramming についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by