I am getting different outputs when using lsim vs ode45 when solving second order coupled differential equations
Show older comments
I have a model of a spring-mass-damper system that I have already solved numerially using the ode45 function. However, I would like to add controls to the system and thus have made an "equivalent" state space model. I checked the algebra a bunch and cant figure out why I am getting different responses with the lsim function vs the ode45 method. I have attached my code here.
%Define the parameters and system matrices as before
global g c k L m M Io f tau wn Ig K wb q z alpha
g=1.62; %lunar gravity
tau=-0.005; %envelope function 1/time constant
wn=117; %natural frequency of regolith foundation
m=2187500; %regolith foundation mass
M=3000; %telescope mass (used from paper provided)
Ig=1500; %Moment of Inertia for telescope Used Ig=1/2*M*R^2 assumed radius of 1m
Io=(M*L^2)+Ig;
c=42485.625; %damping coefficient
L=10; %length of telescope
k=29.96*(10^9); %spring constant of regolith
K=7*(10^10); %spring constant of aluminum
wb=482; %angular velocity of seismic input
q=M+m;
z=(M^2)*(L^2);
alpha=Io*(q)-z;
% Define the state-space matrices
% Define the state-space matrices
A = [0, 1, 0, 0; (-Io * k / alpha), (-Io * c / alpha), ((M * L * K - z * g) / alpha), 0; 0, 0, 0, 1; ((M * L * k) / alpha), ((M * L * c) / alpha), (((M * L * g *q) - (K*q)) / alpha), 0];
B = [0; (Io / alpha); 0; (-M * L / alpha)];
C = [1, 0, 0, 0];
C2= [0, 0, 1, 0];
D = [0];
% Define the time vector
t = linspace(0, 900, 1000000); % Adjust the time vector as needed
% Define the input signal
u= ((k.*exp(tau.*t).*sin(wb.*t))+c.*(((tau.*exp(tau.*t).*sin(wb.*t))+(wb.*exp(tau.*t).*cos(wb.*t)))));
sys=ss(A,B,C,D)
sys2=ss(A,B,C2,D)
y=lsim(sys,u,t);
y2=lsim(sys2,u,t);
figure
subplot(2,1,1)
plot(t,y)
xlabel('Time (s)')
ylabel('X Displacement (m)')
grid on
subplot(2,1,2)
plot(t,y2)
xlabel('Time (s)')
ylabel('$\theta$ Displacement (rad)')
%
%% ODE METHOD
global g c k L m M Io f tau wn Ig K wb q z
g=1.62; %lunar gravity
tau=-0.005; %envelope function 1/time constant
wn=117; %natural frequency of regolith foundation
m=2187500; %regolith foundation mass
M=3000; %telescope mass (used from paper provided)
Ig=1500; %Moment of Inertia for telescope Used Ig=1/2*M*R^2 assumed radius of 1m
Io=(M*L^2)+Ig;
c=42485.625; %damping coefficient
L=10; %length of telescope
k=29.96*(10^9); %spring constant of regolith
K=7*(10^10); %spring constant of aluminum
wb=117; %angular velocity of seismic input
q=M+m;
z=(M^2)*L^2;
f= @(time) ((k*exp(tau*time)*sin(wb*time))+c*(((tau*exp(tau*time)*sin(wb*time))+(wb*exp(tau*time)*cos(wb*time)))));
%Initial Conditions
x0=0;
v0=0;
theta0=0;
omega0=0;
IC=[x0,theta0,v0,omega0];
%Time Span (seconds)
t0=0;
tf=700;
tspan=[t0,tf];
% Numerical Integration (Both Portions)
%Linear Portion
[timeL,state_valuesL] = ode45(@linear,tspan,IC);
xL = state_valuesL(:,1);
vL = state_valuesL(:,2);
thetaL = state_valuesL(:,3);
omegaL = state_valuesL(:,4);
% Plotting the Results
figure
subplot(2,1,1)
plot(timeL,xL), ylabel('Displacement (m)')
title('X Displacement vs. Time (Linear)')
grid on
subplot(2,1,2)
plot(timeL,thetaL),ylabel('Angular Dispalcement (rad)')
title('$\theta$ Angular Displacement vs. Time (Linear)')
grid on
%print -depsc 2DOF_482
% Linear Function
function SD_L = linear(T,S)
global g c k L m M Io f tau wn Ig K wb y yprime q z alpha
SD_L = [S(2);
(-Io*k/alpha)*S(1)+(-Io*c/alpha)*S(2)+((M*L*K-z*g)/alpha)*S(3)+(Io/alpha)*f(T);
S(4);
(M*L*k/alpha)*S(1)+(M*L*c/alpha)*S(2)+((M*L*g*q-K*q)/alpha)*S(3)-(M*L/alpha)*f(T)];
end
Accepted Answer
More Answers (0)
Categories
Find more on Programming 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!
