plotting nonlinear system with constant input

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

답변 (1개)

Walter Roberson
Walter Roberson 2012년 7월 3일

1 개 추천

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

Eka
Eka 2012년 7월 3일
what must I do to make the equation is correct?n how I declare function of 'x' or dimension of 'x'?thank you
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
Eka 2012년 7월 4일
after running, your code with mine is same,and the figure of simulation before and after linearization nothing difference...what's wrong with this function?
I got equation above from a half suspension system and I give the road bump disturbance as high as 5 cm, what must I do to run the program with nothing error?yhank you

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Variables에 대해 자세히 알아보기

태그

질문:

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