Mass spring damper system not working
I’m solving an ode45 for a mass spring damper system as shown below. But the results im getting don’t oscillate eventhough the input is an sinus. I have seen other questions about this (link) but can not get it to work. All help is apprecriated, thanks.
clc;
close all;
clear;
%Mass
m_total =[ 363.5 463.7 363.5 ; 563.9 663.1 563.9 ; 764.3 864.5 764.3];
m = m_total(2,:);
% Staitionary frequency
w = 5;
%Constants for springs
k = 40;
b = 0.2;
t = [0 20];
x0 = [0, 0, 0, 0, 0, 0, 0];
[Time,x] = ode45(@(t,x)MassSpringFunction(t,x,m,w,k,b),t,x0);
figure(1)
plot(Time,x(:,1))
hold on
plot(Time,x(:,3))
plot(Time,x(:,5))
legend("U1" , "U2" , "U3")
hold off
function dxdt = MassSpringFunction(t, x, m, w, k, b)
% Acceleration of 10 hz/s
Freq = 2*pi*10*t;
if w > Freq % Acceleration of frequency
xin = sin(Freq.*t);
else % Stationairy input
xin = sin(2*pi*w.*t);
end
dxdt = [zeros(6,1);xin];
% Velocities
dxdt(1) = x(4);
dxdt(2) = x(5);
dxdt(3) = x(6);
% Positions
dxdt(4) = k/m(1) .* (x(1) – xin) + k/m(1).*(x(1)-x(2)) – b/m(1).*x(4);
dxdt(5) = k/m(2) .* (x(2) – x(1)) + k/m(2).*(x(2)-x(3)) – b/m(2).*x(5);
dxdt(6) = k/m(3) .* (x(3) – x(2)) + k/m(3).*(x(3)) – b/m(3).*x(6);
endI’m solving an ode45 for a mass spring damper system as shown below. But the results im getting don’t oscillate eventhough the input is an sinus. I have seen other questions about this (link) but can not get it to work. All help is apprecriated, thanks.
clc;
close all;
clear;
%Mass
m_total =[ 363.5 463.7 363.5 ; 563.9 663.1 563.9 ; 764.3 864.5 764.3];
m = m_total(2,:);
% Staitionary frequency
w = 5;
%Constants for springs
k = 40;
b = 0.2;
t = [0 20];
x0 = [0, 0, 0, 0, 0, 0, 0];
[Time,x] = ode45(@(t,x)MassSpringFunction(t,x,m,w,k,b),t,x0);
figure(1)
plot(Time,x(:,1))
hold on
plot(Time,x(:,3))
plot(Time,x(:,5))
legend("U1" , "U2" , "U3")
hold off
function dxdt = MassSpringFunction(t, x, m, w, k, b)
% Acceleration of 10 hz/s
Freq = 2*pi*10*t;
if w > Freq % Acceleration of frequency
xin = sin(Freq.*t);
else % Stationairy input
xin = sin(2*pi*w.*t);
end
dxdt = [zeros(6,1);xin];
% Velocities
dxdt(1) = x(4);
dxdt(2) = x(5);
dxdt(3) = x(6);
% Positions
dxdt(4) = k/m(1) .* (x(1) – xin) + k/m(1).*(x(1)-x(2)) – b/m(1).*x(4);
dxdt(5) = k/m(2) .* (x(2) – x(1)) + k/m(2).*(x(2)-x(3)) – b/m(2).*x(5);
dxdt(6) = k/m(3) .* (x(3) – x(2)) + k/m(3).*(x(3)) – b/m(3).*x(6);
end I’m solving an ode45 for a mass spring damper system as shown below. But the results im getting don’t oscillate eventhough the input is an sinus. I have seen other questions about this (link) but can not get it to work. All help is apprecriated, thanks.
clc;
close all;
clear;
%Mass
m_total =[ 363.5 463.7 363.5 ; 563.9 663.1 563.9 ; 764.3 864.5 764.3];
m = m_total(2,:);
% Staitionary frequency
w = 5;
%Constants for springs
k = 40;
b = 0.2;
t = [0 20];
x0 = [0, 0, 0, 0, 0, 0, 0];
[Time,x] = ode45(@(t,x)MassSpringFunction(t,x,m,w,k,b),t,x0);
figure(1)
plot(Time,x(:,1))
hold on
plot(Time,x(:,3))
plot(Time,x(:,5))
legend("U1" , "U2" , "U3")
hold off
function dxdt = MassSpringFunction(t, x, m, w, k, b)
% Acceleration of 10 hz/s
Freq = 2*pi*10*t;
if w > Freq % Acceleration of frequency
xin = sin(Freq.*t);
else % Stationairy input
xin = sin(2*pi*w.*t);
end
dxdt = [zeros(6,1);xin];
% Velocities
dxdt(1) = x(4);
dxdt(2) = x(5);
dxdt(3) = x(6);
% Positions
dxdt(4) = k/m(1) .* (x(1) – xin) + k/m(1).*(x(1)-x(2)) – b/m(1).*x(4);
dxdt(5) = k/m(2) .* (x(2) – x(1)) + k/m(2).*(x(2)-x(3)) – b/m(2).*x(5);
dxdt(6) = k/m(3) .* (x(3) – x(2)) + k/m(3).*(x(3)) – b/m(3).*x(6);
end ode45 MATLAB Answers — New Questions