plotting nonlinear system with constant input
Show older comments
I want to plot nonlinear system,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
>>[t,y]=ode45('suspension',[0 10],[0;0;0;0;0;0;0;0]);
>>plot(t,y(:,1));
is it true for my task?thank you
Answers (1)
Walter Roberson
on 3 Jul 2012
1 vote
No, that is not correct, or at least it is not clear. Please read http://www.mathworks.com/help/techdoc/math/bsgprpq-5.html
3 Comments
Eka
on 3 Jul 2012
Walter Roberson
on 3 Jul 2012
function dx = suspension(t, x, Mb, Mf, Mr, I, Ksf, Ksr, Ktf, Ktr, Csf, Csr, Lf, Lr, Wf, Wr)
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
And to invoke it,
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;
objfun = @(t,x) suspension(t, x, Mb ,Mf, Mr, I, Ksf, Ksr, Ktf, Ktr, Csf, Csr, Lf, Lr, Wf, Wr);
[t,y]=ode45(objfun, [0 10], [0;0;0;0;0;0;0;0]);
Note though that your assignment to "y" inside "suspension" is not doing anything useful. "y" is a local variable there, and its value is not being used to create any output argument, so the value of "y" will be discarded once the function ends.
I made no attempt to examine the mathematics of your "dx" calculation. You did not indicate the system of ODE's that you are working with, so all I can do is examine the syntax of the calculation. The changes I made to "suspension" itself are cosmetic, but necessary if one is to have any realistic hope of figuring out what it is doing. Whitespace is important in programming!!
Eka
on 4 Jul 2012
Categories
Find more on Variables in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!