plotting nonlinear system with constant input

Asked by Eka on 3 Jul 2012
Latest activity Answered by Walter Roberson on 6 Jul 2012

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 Comments

Eka on 3 Jul 2012

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 on 3 Jul 2012

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 on 5 Jul 2012

error comment "variable x undefined " and dx=x(5) error

Eka

Products

No products are associated with this question.

1 Answer

Answer by Walter Roberson on 6 Jul 2012

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.

Code using the anonymous function is shown in http://www.mathworks.com/matlabcentral/answers/42590-plotting-nonlinear-system-with-constant-input

0 Comments

Walter Roberson

Contact us