# Plotting a SHO in matlab [closed]

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

-

## closed as off-topic by tpg2114, Qmechanic♦Nov 3 '13 at 2:26

This question appears to be off-topic. The users who voted to close gave this specific reason:

• "Homework-like questions should ask about a specific physics concept and show some effort to work through the problem. We want our questions to be useful to the broader community, and to future users. See our meta site for more guidance on how to edit your question to make it better" – tpg2114, Qmechanic
If this question can be reworded to fit the rules in the help center, please edit the question.

Do you just want to use matlab for plotting, or do you want to numerically simulate the oscillations? – Colin K Apr 2 '11 at 18:38
Do you understand the physics and only have trouble with programming? If so, I'd suggest moving this to some programming related site. But if you are interested in physics, we might help you. – Marek Apr 2 '11 at 18:48
Colin - I have to plot a x/t-diagram using matlab. – user2905 Apr 2 '11 at 19:07
Marek - I need some help with the physics part too. I understand the formula: x(t)=A*cos(wt+delta) is very important in this case, but I don't know how I'm supposed to go from there. – user2905 Apr 2 '11 at 19:14

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).

-