how to use ss and lsim for 1 dof differential equation

5 visualizaciones (últimos 30 días)
Hiroki
Hiroki el 1 de En. de 2021
Comentada: Hiroki el 2 de En. de 2021
i want to solve 1 dof differential equation by using ss and lsim for just as an example.
probrem is the result calculated by ss&lsim and the result calcuated by matmatically analitically caliculation are different.
do you know why this things happen? if my code has some mistake, I want to know where is prob.
Best,
hiroki
---code---
M=4;
C=0;
K=2500;
A=[0 1; -K/M -C/M];
B=[0;1/M];
C=[1 0];
D=0;
sys=ss(A,B,C,D)
dt=0.001;
t=dt*[1:100];
w=100;
f=2*cos(w*t);
u=f;
x=2/(K-M*w^2)*cos(w*t);
y = lsim(sys,u,t);
plot(t,u)
hold on
yyaxis right
plot(t,y)
hold on
yyaxis right
plot(t,x);
legend('u:input','y:sys solution','x: analitical solution')

Respuesta aceptada

Paul
Paul el 1 de En. de 2021
That lsim command calculates y using default initial conditions x(0) = xdot(0) = 0, but the analytical solution clearly doesn't satisfy those initial conditions. It looks like that solution satisfies the initial conditions x(0) = 2/(K-M*w^2), xdot(0) = 0. Try this:
y1 = lsim(sys,u,t,[2/(K-M*w^2) 0]);
and compare to x and y.
Alos, why not define t starting from 0?
t = dt*[0:100]
  1 comentario
Hiroki
Hiroki el 2 de En. de 2021
thank you so much! it works! your answer is perfect. I made two mistakes. first is initial condition of x(0) and second is starting definition of t!! thank!

Iniciar sesión para comentar.

Más respuestas (0)

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by