Main Content

Double Spring-Mass System

R2026b

This example shows how to model a double spring-mass mechanical system with a periodically varying forcing function. A spring connects the two masses, and the force is applied to the left mass. The force causes both masses to move and interact through the spring.

Two rectangular masses connected by a spring. The left mass, labeled mass₁, is pushed to the right by an input force u(t), represented by a blue arrow. The spring between the masses is labeled kₐ. The right mass is labeled mass₂

The Simulink® model represents a double mass-spring mechanical system controlled using state‑feedback with a linear-quadratic regulator (LQR) controller and a state estimator.

Plant Block

The State-Space block named Plant implements the double spring-mass mechanical system, represented by these state-space equations:

x˙=Ax+Buy=Cx+Du

with the state vectors defined as:

x=[x1x˙1x2x˙2] and y=[x1x2]

Matrices A, B, C, and D contain the coefficients that define the terms in the mechanical system equations of motion.

A=[0100-kam10kam100001kam20-kam20]B=[01m100]C=[10000010]D=[00]

where:

  • x1,x˙1 – Position and velocity of mass 1, respectively

  • x2,x˙2 – Position and velocity of mass 2, respectively

  • u(t) – Periodic forcing function

  • ka – Spring constant

The plant output provides the measured positions, which the model uses both for visualization and for state estimation.

Estimator Block

The model implements state‑feedback with an LQR controller and a state estimator. The State-Space block named Estimator implements the state estimator. The block estimates the full state vector using the plant input and measured output. The estimator continuously compares the predicted output to the measured output and corrects the state estimates based on the difference. For more information about LQR control, see lqr (Control System Toolbox).

Model Simulation

Open and simulate the model. To animate the mass system during simulation, the model uses a Level-2 MATLAB S-Function block.

open_system('sldemo_dblcart1');

Figure dblcart1 Animation contains an axes object and other objects of type uicontrol. The hidden axes object contains 32 objects of type line.

sim('sldemo_dblcart1');
close(findall(0,'Type','figure'))

See Also

| | (Control System Toolbox)

Topics

Teaching Resources