Plotting a SHO in matlab I have no prior experience of using matlab. My teacher want me to solve this question. I have been trying for a couple of hours now with no luck, please help!
The mass of 100 g hanging in a spring with spring constant 40 N / m. The mass is set into vibration by the spring is stretched 14 mm. Neglecting any energy loss.
Use MATLAB and plot a graph showing the distance from the equilibrium position as
function of time with initial conditions x(0) = 14 mm and v (0) = 0 mm/s
 A: Addressing just the physics part (go to stack overflow for the programming), and using the equation that you've been given:
$$ x(t) = A \cos \left( \omega t + \delta \right) $$
Let's look at the form of the solution.


*

*It is sinusoidal

*The curve will have a maximum value of $A$ (because cosine has a maximum value of 1)

*When $\delta$ is $0, \pm 2\pi, \pm 4\pi \dots$ the maximum will occur at $t = 0, \pm \frac{2\pi}{\omega}, \pm \frac{4\pi}{\omega} \dots$, and will move around by $-\delta$. So we conclude that $\delta$ controls the phase of the oscillation.

*We call $\omega$ the angular frequency of the oscillation and find that the period is $T = \frac{2\pi}{\omega}$.


With that, lets look at your initial conditions and see if we can fill in some of those variables...


*

*The string starts stretched down from the equilibrium position. I'm going to call that the $-x$ direction. So $x(0) = -14$ rather than $+14$ as you wrote (but that is just a detail  of the coordinate system I've chosen).

*Will the weight ever move farther down that the starting position? What does that tell you about $A$ and $\delta$?


That leaves us with $\omega$ as an unknown. I presume you've been shown a derivation of simple harmonic oscillation, and already know that for a mass on a spring
$$ \omega = \sqrt{ \frac{k}{m} }$$. If you have not look at my answer to Explanation: Simple Harmonic Motion (or indeed several of the other answers to that question).
