MATLAB Scientific Academy
INTERMEDIATE · 25 min

Model a damped oscillator

Explore a familiar physical system by expressing its motion as a differential equation and comparing model parameters.

What you will learn

  • Identify the role of mass, damping and stiffness.
  • Understand a second-order oscillator model.
  • Plot displacement against time.

The concept

A damped mass-spring system follows m ẍ + c ẋ + kx = 0. The mass m sets inertia, damping c removes energy, and stiffness k pulls the mass back toward equilibrium.

Numerical ODE solvers such as ode45 approximate the system over time. Rewrite the second-order equation as two first-order equations for displacement and velocity, then pass the derivative function to the solver.

Scientific habit: Before running a program, predict what it will do. Then compare your prediction with the output and explain any difference.

Worked example

A basic ode45 example for a mass-spring-damper system.

example.mMATLAB CODE
m = 1; c = 0.35; k = 9;
f = @(t, z) [z(2); -(c/m)*z(2) -(k/m)*z(1)];
tspan = [0 10];
z0 = [1; 0]; % initial displacement, velocity
[t, z] = ode45(f, tspan, z0);
plot(t, z(:,1), 'LineWidth', 2);
xlabel('Time (s)'); ylabel('Displacement (m)'); grid on;

Try increasing c to observe stronger damping. Keep parameter units consistent and state initial conditions explicitly.

Try it yourself

Use the physical meaning of the model to predict the result.

Quick check

What generally happens to the oscillation amplitude when positive damping is increased?

Reveal hint and answer
Hint: Damping removes mechanical energy from the system.
Answer: The oscillations decay more rapidly.

Where this is used

Related models appear in mechanical vibration, resonators, laser dynamics, control systems and many coupled physical systems.

Academy homeNext: Light & optical systems