Modelling of Free Oscillations of Mass Spring System 

 March 25, 2022

By  Shubham

Modelling of Free Oscillations of a Mass-Spring System


Linear ordinary differential equations have critical applications in mechanical systems and electrical systems. In this blog, we will try to model and solve a simple mechanical system that will consist of a mass suspended on an elastic spring, also known as a "mass-spring system". The blog is in two parts. In the first part, we will start by setting up our mass-spring system with ideal conditions, i.e., having undamped motion. While in the second part, we will make our model realistic by introducing damping to our system. We will also discuss the three cases of damping.

Setting up the Mass-Spring Model

Start by considering a mass suspended on an ordinary coil spring that resists compression and extension. The spring is suspended from a fixed support.

Mass-spring image

Mass spring system

Assuming that we pull down the mass by an amount y>0, then, according to Hooke's law, there will be a spring force F_{1}=-ky.

Here k(>0) is the spring constant. The negative sign indicates that the direction of force F_{1} is upward. There is also an additional force (-F_{o}) in the spring. However, F_{o} does not affect the motion because it is in equilibrium with the weight of the ball, i.e., -F_{o}=W=mg

The motion of this mass-spring system can be determined by Newton's second law of motion, mass\times acceleration = my''=Force.

Forming the ODE of Undamped System

For now, we will consider that the damping of our system is minimal and, therefore, can be neglected. If we consider the motion of the system over a short time, then Newton's law gives the model my''=-F_{1}=-ky; thus


The above equation is a homogeneous linear ODE and can be solved to obtain the general solution

y(t)=Acos\omega _{o}t+Bsin\omega _{o}t;    \omega_{o}= \sqrt{\frac{k}{m}}

This motion of the mass-spring system is called a harmonic oscillation and has the frequency f=\frac{\omega _{o}}{2\pi }Hertz^{3}.

Implementing the Model of Mass-Spring System in MATLAB

Let's implement this model of simple harmonic motion in MATLAB and check the results. We will start with the following initialization condition:

% Initialization
W = 98;                              % weight of ball = 98nt
k = W/1.09;                        % spring constant
g = 9.8;                               % acceleration due to gravity
m = W/g;                            % mass of ball
w0 = sqrt(k/m);

Get Access to

We all came across the infamous mass-spring system during our physics classes. This time we will revisit it with the visualization power of MATLAB; Developed in MATLAB R2018a with Symbolic toolbox.

Now we will define the symbolic function for y(t) and will try to solve the ODE my''+ky=0 for the initial conditions y(0)=A=0.16 and y'(0)=\omega _{o}B=0. We will use the dsolve() function to solve the equation and get a particular solution.

Finally, we will plot the equations to get our graph of simple harmonic oscillations of our mass-spring system. Keep in mind that the t has a short-range (usually in seconds). Also, convert the values of the solution of ODE into a double type variable otherwise, MATLAB will give you an error.

On running the code, you should get a graph like the following.


Undamped oscillations of Mass-spring system

Introducing damping to the system

Now, lets introduce the damping force F_{2}=-cy' to our system my''=-ky where c is the damping constant. The ODE of this damped mass-spring system is my''+cy'+ky=0. This damping force can be physically introduced by connecting the ball to a dashpot. Let \lambda=y'' , then the ODE can be represented as \lambda^{2}+\frac{c}{m}\lambda +\frac{k}{m}=0. This equation is a quadratic equation and upon solving it, we get the roots as \lambda_{1}=-\alpha +\beta ,\lambda_{2}=-\alpha -\beta . Here \alpha= \frac{c}{2m} and \beta=\frac{1}{2m} \sqrt{c^{2}-4mk}. Depending upon the value of c, there will be three cases of damping.

Case 1: Over damping

If the damping constant c is very large (c^{2}>4mk), then \lambda_{1} and \lambda_{2} become two distinct real roots and the general solution thus obtained for the ODE is,

y(t)=c_{1}e^{-(\alpha -\beta )t}+c_{2}e^{-(\alpha +\beta)t}

Here, for t>0, both the exponents have a negative value and hence both terms approach zero. Practically, the mass will be at rest at the static equilibrium position after a long time.

Case 2: Critical damping

This case occurs when the roots of the equation are equal or we can say that c^{2}=4mk. The general solution of the ODE is

y(t)=(c_{1}+c_{2}t)e^{-\alpha t}

Critical damping is usually the case between nonoscillatory motions and oscillations.

Case 3: Under damping

This case occurs when the damping constant c is very small that is, c^{2}<4mk. Here, \beta is imaginary,

\beta =i\omega ^{*}

Here, \omega ^{*}=\frac{1}{2m}\sqrt{4mk-c^{2}}

The roots of the quadratic equation are complex conjugates and the corresponding general equation of the ODE is,

y(t)=e^{-\alpha t}(Acos\omega ^{*}t+Bsin\omega ^{*}t)=Ce^{-\alpha t}cos(\omega ^{*}t-\delta )

This case represents the actual damped oscillations.

Implementing the damped model of mass-spring system

We will start by introducing the damping constants to the initialization condition.

We will also introduce the new differential equations due to the three damping constants. Also, change the required lines that are used for solving the differential equations. Again, we are using the dsolve() function to solve the ODEs.

Now, just plot the graphs of these equations. This time we will also turn on legends so that we can differentiate between the different graphs and check which one belongs to over damping, critical damping and under damping.

Now, lets run the code and check our results.

damped oscillations result

Damped oscillations of a Mass-spring System

Unlike the undamped mass-spring system, here, the system comes to rest after some time has passed.


We have created an ideal mass-spring system with an ODE for our undamped system. We also implemented our system in MATLAB and got the desired results. We also introduced damping to this system. We discussed the three damping cases, i.e., overdamping, critical damping, and under damping, and checked its effects on the system using MATLAB.


Mass-spring systems are the fundamental bodies used in modelling and solving certain engineering problems related to designing certain structures. Some of these problems are understanding the working of pendulums, designing the suspension systems of vehicles, analyzing the building response to an earthquake. The damped mass-spring systems are also employed to study certain designs' rigid body dynamics.

Get instant access to the code, model, or application of the video or article you found helpful! Simply purchase the specific title, if available, and receive the download link right away! #MATLABHelper #CodeMadeEasy

Ready to take your MATLAB skills to the next level? Look no further! At MATLAB Helper, we've got you covered. From free community support to expert help and training, we've got all the resources you need to become a pro in no time. If you have any questions or queries, don't hesitate to reach out to us. Simply post a comment below or send us an email at [email protected].

And don't forget to connect with us on LinkedIn, Facebook, and Subscribe to our YouTube Channel! We're always sharing helpful tips and updates, so you can stay up-to-date on everything related to MATLAB. Plus, if you spot any bugs or errors on our website, just let us know and we'll make sure to fix it ASAP.

Ready to get started? Book your expert help with Research Assistance plan today and get personalized assistance tailored to your needs. Or, if you're looking for more comprehensive training, join one of our training modules and get hands-on experience with the latest techniques and technologies. The choice is yours – start learning and growing with MATLAB Helper today!

Education is our future. MATLAB is our feature. Happy MATLABing!

About the author 


I have done my bachelor degree in electronics from University of Delhi. I like to tinker with the hardware to understand how it actually works.

{"email":"Email address invalid","url":"Website address invalid","required":"Required field missing"}

MATLAB Helper ®

Follow: YouTube Channel, LinkedIn Company, Facebook Page, Instagram Page

Join Community of MATLAB Enthusiasts: Facebook Group, Telegram, LinkedIn Group

Use Website Chat or WhatsApp at +91-8104622179