Filter löschen
Filter löschen

Solve the differential equations for three masses attached together by springs.

46 Ansichten (letzte 30 Tage)
I need help to solve the following task about the Mechanical Vibrations:
  • Write equations of motion (three of them)
  • Express the equations of motion as a system of differential equations.
  • consider three masses m1, m2, and m3 attached together by springs as shown in figure.
  • Use MATLAB to write a program that numerically solve the differential equation. Use the different types of initial conditions to simulate the behavior of the mass.
Thank you for you help!

Antworten (1)

Shivansh am 4 Jan. 2024
Hi Suthakamol,
I understand that you are trying to model a mass-spring model with three masses connected to spring in a 1-d line. You can use Matlab to model this problem and plot graphs to analyse the impact of different initial conditions to simulate the behaviour of the mass blocks.
I am assuming no damping for the simplicity of the problem. Let x1, x2, and x3 be the initial displacements of mass objects from the equilibrium positions. The equations of motion using Newton’s second law and Hooke’s law will be
For m1: m1 * d^2x1/dt^2 = -k1 * x1 + k2 * (x2 - x1)
For m2: m2 * d^2x2/dt^2 = -k2 * (x2 - x1) + k3 * (x3 - x2)
For m3: m3 * d^2x3/dt^2 = -k3 * (x3 - x2) - k4 * x3
The next step will be to represent this system of equations into first order differential equations to solve this system.
Assuming v = dx/dt and v1=dx1/dt and so on.
dv1/dt = (-k1 * x1 + k2 * (x2 - x1)) / m1
dv2/dt = (-k2 * (x2 - x1) + k3 * (x3 - x2)) / m2
dv3/dt = (-k3 * (x3 - x2) - k4 * x3) / m3
You can refer to below code for Matlab implementation of the above problem and can tweak the initial conditions to analyse the change with the help of the plots.
function mechanical_vibrations()
% Define the parameters
m1 = 1; m2 = 1; m3 = 1; % masses
k1 = 10; k2 = 10; k3 = 10; k4 = 10; % spring constants
% Initial conditions [x1, v1, x2, v2, x3, v3]
initial_conditions = [0.1, 0, -0.1, 0, 0.05, 0]; % Example initial conditions
% Time span
tspan = [0, 10]; % From 0 to 10 seconds
% Solve the system of ODEs using ODE45
[t, Y] = ode45(@(t, y) odefcn(t, y, m1, m2, m3, k1, k2, k3, k4), tspan, initial_conditions);
% Plot the results
plot(t, Y(:, 1), 'b', t, Y(:, 3), 'r', t, Y(:, 5), 'g');
title('Displacements of Masses Over Time');
xlabel('Time (s)');
ylabel('Displacement (m)');
function dydt = odefcn(t, y, m1, m2, m3, k1, k2, k3, k4)
dydt = zeros(6, 1);
dydt(1) = y(2);
dydt(2) = (-k1 * y(1) + k2 * (y(3) - y(1))) / m1;
dydt(3) = y(4);
dydt(4) = (-k2 * (y(3) - y(1)) + k3 * (y(5) - y(3))) / m2;
dydt(5) = y(6);
dydt(6) = (-k3 * (y(5) - y(3)) - k4 * y(5)) / m3;
You can refer to the following Matlab documentation link for more information on “ode45” function:
Hope it helps!


Mehr zu Programming finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by