Wiki Markup |
---|
{include: ANSYS Google Analytics}
h1. Spring-Mass Harmonic Oscillator in MATLAB
Consider a spring-mass system shown in the figure below.
\\
\\ [!spring_mass.png|width=350!|^spring_mass.png]\\
\\
Applying _F = ma_ in the x-direction, we get the following differential equation for the location x(t) of the center of the mass:
{latex}
\[
m \ddot{x} + k x =0
\]
{latex}
The initial conditions at _t=0_ are
{latex}
\[
x(0)=1,
\]
{latex}
and
{latex}
\[
v(0)=\dot{x} ̇(0)=0
\]
{latex}
The first condition above specifies the initial location _x(0)_ and the second condition, the initial velocity _v(0)_.
\\
We'll solve this differential equation numerically, i.e. integrate it in time starting from the initial conditions at t=0, using MATLAB. We'll use Euler's method to perform the numerical integration. We'll also make a plot of the position vs. time and compare it to the analytical solution.
[*Go to Step 1: Euler Integration*|SIMULATION:Spring-Mass System - Euler Integration]
[Go to all MATLAB Learning Modules|SIMULATION:MATLAB Learning Modules]
|
...
Widget Connector |
---|
width | 600 |
---|
url | https://www.youtube.com/watch?v=uXURYBVEv-c |
---|
height | 370 |
---|
|
Widget Connector |
---|
width | 600 |
---|
url | https://www.youtube.com/watch?v=IyRJmOd48NE |
---|
height | 370 |
---|
|
The following video shows how to implement the Euler's integration method for one time-step.
Widget Connector |
---|
width | 600 |
---|
url | https://www.youtube.com/watch?v=3khcp_ZjnaU |
---|
height | 370 |
---|
|
We extend our script to perform the Euler integration over multiple time-steps by looping over the appropriate statements as shown in the video below.
Widget Connector |
---|
width | 600 |
---|
url | https://www.youtube.com/watch?v=OaGJsamM8rw |
---|
height | 370 |
---|
|
Our script saves only the final location of the mass. We are also interested in saving the intermediate locations so that we can make a plot of position vs. time. We do this by creating arrays for the position and time as shown in the video below.
...