MATLAB Simulations

I learned MATLAB back when I was in university and used it to simulate some simple physical systems. Below are the video snippets. You can find the m files of the simulations in the "m files" subpage from the drop-down menu of this page's tab above. Feel free to download and reuse them, but please acknowledge this website.

1. Bouncing ball - Simulates a bouncing ball. Solves basic kinematic equation. Initial inputs - speed and coefficient of restitution.

2. Projectile motion - Simulates projectile motion in 2D. Solves basic kinematic equation. Initial inputs - speed of launch, angle of launch, coefficient of restitution.

3. Simple Harmonic Motion - Simulates SHM in 1 dimension. Initial inputs - amplitude, mass and spring constant.

4. Circular motion in 3D - Simulates circular motion of a body in 3D, using the rotation matrix. Initial inputs - position vector, velocity vector of body.

5. 2 body simulation under gravity - Simulates motion of 2 bodies under the action of only mutual gravitational forces. Applies Newton's Laws and solves the second order differential equations. Initial inputs - masses, position vectors and velocity vectors of both the bodies. (Note: Universal Gravitational Constant G has been scaled to get results that can be plotted).

Binary star system -

Planet and star system -

Slingshot effect -

6. 3 body simulation under gravity - Simulates motion of 3 bodies under the action of only mutual gravitational forces. Applies Newton's Laws and solves the second order differential equations. Initial inputs - masses, position vectors and velocity vectors of both the bodies. (Note: Universal Gravitational Constant G has been scaled to get results that can be plotted).

7. Wave packets

i) Wave packet simulation - Simulates wave packets formed from superposition of two sinusoidal waves. Clearly shows the phase velocity and group velocity of the wave packet; And shows the difference between these two types. Initial inputs - amplitude, angular frequency, angular wave number.

Wave packet when group velocity is equal to phase velocity -

Wave packet when group velocity is greater than phase velocity -

Wave packet when group velocity is smaller than phase velocity -

ii) Wave packet evolution - Simulates the evolution of a wave packet as a superposition of an increasing number of sinusoidal waves with time. Initial inputs - amplitude, angular frequency, angular wave number, number of waves to be superposed.

8. Polar coordinate plot - A very short code that shows the power of polar coordinates over Cartesian coordinates in drawing complicated (and beautiful) curves.