plotting nonlinear system with constant input

if I enter function in M-file like that:
function dx = suspension(t,x,Mb,Mf,Mr,I,Ksf,Ksr,Ktf,Ktr,Csf,Csr,Lf,Lr,Wf,Wr)
Mb=730;
Mf=40;
Mr=36;
I=1230;
Ksf=19960;
Ksr=17500;
Ktf=175500;
Ktr=175500;
Csf=1290;
Csr=1620;
Lf=1;
Lr=(1.8);
Wf=0.05;
Wr=0.05;
dx=zeros(8,1); %Wf and Wr is constant input as road bump
dx = [x(5);
x(6);
x(7);
x(8);
1/Mb*((-Ksf-Ksr)*x(1)+Ksf*x(2)+Ksr*x(3)-Lf*Ksf*sin(x(4))+Lr*Ksr*sin(x(4))-Lf*Csf*x(8)*cos(x(4))+Lr*Csr*x(8)*cos(x(4))-(Csf+Csr)*x(5)+Csf*x(6)+Csr*x(7));
1/Mf*(Ksf*x(1)-(Ksf+Ktf)*x(2)+Lf*Ksf*sin(x(4))+Lf*Csf*x(8)*cos(x(4))+Csf*x(5)-Csf*x(6)+Ktf*Wf);
1/Mr*(Ksr*x(1)-(Ksr+Ktr)*x(3)-Lr*Ksr*sin(x(4))-Lr*Csr*x(8)*cos(x(4))+Csr*x(5)-Csr*x(7)+Ktr*Wr);
1/I*((-Lf*Ksf+Lr*Ksr)*x(1)+Lf*Ksf*x(2)-Lr*Ksr*x(3)-Lf*Lf*Ksf*sin(x(4))-Lr*Lr*Ksr*sin(x(4))-Lf*Lf*Csf*x(8)*cos(x(4))-Lr*Lr*Csr*x(8)*cos(x(4))-(Lf*Ksf-Lr*Csr)*x(5)+Lf*Csf*x(6)-Lr*Csr*x(7))];
y=[x(2);x(3)];%output
end
>>[t,y]=ode45('suspension',[0 10],[0;0;0;0;0;0;0;0]);
>>plot(t,y(:,1));
what must I add in order to function running is true?

4 件のコメント

the cyclist
the cyclist 2012 年 7 月 3 日
I was able to run your code without error. I don't understand the question you are asking. Are you able to write a little bit more explanation?
Eka
Eka 2012 年 7 月 3 日
it's right if I run in command windows,but it's error if I run in M-file,..can you help me?thank you
Walter Roberson
Walter Roberson 2012 年 7 月 3 日
You are going to have to show us the .m file that is producing the error, and show us the error message you are getting.
Eka
Eka 2012 年 7 月 5 日
error comment "variable x undefined " and dx=x(5) error

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2012 年 7 月 6 日

0 投票

You are likely running into difficulty because you are using 'suspension' (the string) as the routine for ode45 to invoke, instead of using an anonymous function. When you use a string, the search path for the function is not the same as when you use an anonymous function.

カテゴリ

質問済み:

Eka
2012 年 7 月 3 日

Community Treasure Hunt

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

Start Hunting!

Translated by