Mass-Spring Under Friction and Gravity

Simulates the interaction of a spring and a mass. Gravity is a constant downwards acceleration.
417 Downloads
Updated 30 Apr 2017

View License

Spring-Mass Under Friction and Gravity
Simulink model created by Abdullah Baig at University of Engineering and Technology, Lahore.
For suggestions, feedback and assistance, contact abdullahbaig1618@gmail.com
This Simulink model simulates the interaction of a spring and a mass. Gravity is implemented as a constant downwards acceleration. The system behaves like a pendulum if the spring-constant is sufficiently large.
Physical Entities
There is an anchor, a mass and a spring in the simulation. The mass follows the Newton's laws of motion under the forces applied on it, i.e. the force exerted by the spring, the force due to the gravity and the force of friction. The spring connects the mass to the anchor and applies a force on the mass, depending on its position. All forces, accelerations, velocities and positions are 2-d vectors. The base units are cm, s and kg.
Mass
The mass is made to follow the Newton's laws of motion and classical kinematics. The following equations are used to calculate its position from the forces acting on it.
=> F = Mb*g - kf*v + Fb
=> a = F / Mb
=> v = Vb + int(F)
=> Pos = Posb + int(v)
Here, "F" is the total force acting on the mass, "Mb" is the value of the mass, "g" is the acceleration due to gravity, "kf" is the coefficient of friction, "v" is the instantaneous velocity of the mass, "Fb" is the external force acting on the mass, "a" is the instantaneous aceleration of the mass, "Vb" is the initial velocity of the mass, "Pos" is its instantaneous position, "Posb" is its initial position and int() denotes the integration function.

Spring
The spring follows the Hooke's law with no limits. It takes the instantaneous position of the anchor and the mass and calculates the force exerted on the amss at that position. Its dynamics are defined using the following equations.
=> L = sqrt((Posa-Posb).(Posa-Posb))
=> e = L - Ls
=> Fsb = ks * (Posa-Posb) * e / L
Here, "L" represents the instantaneous length of the spring, "e" is the extension, "Ls" is the initial or natural length of the spring, "Fsb" is the force exreted by the spring on the mass, and "ks" is the spring contant of the spring.

Display
The display block creates an animation of the anchor, the mass and the spring using their positions. The initial position of the mass is marked by a "+". The animation can also be exported to a video file named "output.avi".

Cite As

Abdullah Baig (2024). Mass-Spring Under Friction and Gravity (https://www.mathworks.com/matlabcentral/fileexchange/50946-mass-spring-under-friction-and-gravity), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2009a
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Earth, Ocean, and Atmospheric Sciences in Help Center and MATLAB Answers

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.0.0

Description is updated.

Screen shot is added
Description is updated.
Contact email is added.
License is changed from CC BY to MATLAB Central's default, i.e. BSD 3 clause.