MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

# plotting nonlinear system with constant input

Asked by Eka on 3 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?

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

## Products

No products are associated with this question.