Mass Spring System ode45 with multiple damping values
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Logan Parrish
il 22 Feb 2022
Commentato: Sulaymon Eshkabilov
il 22 Feb 2022
I am working on this problem where I have to model multiple mass spring systems that all have different damping values. My model uses the equation of
with the initial conditions of m = 5 kg, k = 0.5 N/m, and
. I converted this ODE into a system of 1st order ODEs so I could use ode45. I need to model the above equation for when
(overdamped) ,
(critcally damped), and
(underdamped). I am confused on how I could be able to specify the different damping conditions with ode45, I was thinking to use it within a for loop for each value c but I am having errors occur within my ode45 function. Any help would be greatly appreciated.





% Constants
m = 5; % kg
k = 0.5; % N/m
c = [0 , sqrt(4*m*k)-1 , sqrt(4*m*k)+1, sqrt(4*m*k)]; % damping constants
A = 1.00002;
B = 3.16228;
w0 = sqrt(k/m);
t = 20;
% Function
% Let
% u1 = y ---> u1' = y' = u2
% u2 = y' ---> u2' = 1/m*(-k*u1-c*u2)
f = @(t,u) [u(2) ; 1/m*(-k*u(1)-c*u(2))];
fA = @(t) A*cos(w0*t)+B*sin(w0*t);
% IC
u0 = [1 1];
tspan = [0 t];
% Solve
for tspan = [0 t]
[t,u] = ode45(f,tspan,u0);
if abs(c^2) > 4*m*k
plot(t,u(:,1))
end
end
1 Commento
Risposta accettata
Sulaymon Eshkabilov
il 22 Feb 2022
It is realtively easy to attain the issues of solving the exercises for all damping values and plot them all with appropriate legends:
% Constants
m = 5; % kg
k = 0.5; % N/m
c = [0 , sqrt(4*m*k)-1 , sqrt(4*m*k)+1, sqrt(4*m*k)]; % damping constants
A = 1.00002;
B = 3.16228;
w0 = sqrt(k/m);
t = 20;
% IC
u0 = [1 1];
tspan = [0 t];
% Solve, simulate and plot
figure('name', 'One case of damping: c')
for ii=1:numel(c)
f = @(t,u) [u(2) ; 1/m*(-k*u(1)-c(ii)*u(2))];
fA = @(t) A*cos(w0*t)+B*sin(w0*t);
[t,u] = ode45(f,tspan,u0);
if abs(c(ii)^2) > 4*m*k
plot(t,u(:,1))
end
end
grid on; xlabel('time, [s]'), ylabel('Solution, y(t)')
%% OR you can plot all values of c
clearvars
% Constants
m = 5; % kg
k = 0.5; % N/m
A = 1.00002;
B = 3.16228;
w0 = sqrt(k/m);
c = [0 , sqrt(4*m*k)-1 , sqrt(4*m*k)+1, sqrt(4*m*k)]; % damping constants
t = 20;
% IC
u0 = [1 1];
tspan = [0 t];
figure('name', 'All cases of damping: c')
for ii=1:numel(c)
f = @(t,u) [u(2) ; 1/m*(-k*u(1)-c(ii)*u(2))];
fA = @(t) A*cos(w0*t)+B*sin(w0*t);
[t,u] = ode45(f,tspan,u0);
plot(t,u(:,1)), hold all
L{ii} = ['c = ', num2str(c(ii))];
legend(L{:})
end
grid on; xlabel('time, [s]'), ylabel('Solution, y(t)')
2 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Ordinary Differential Equations in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!