# Mathematica: position vs time in a spring

## Homework Statement

Plot the position vs time graph of an object attached to a spring.
m = 0.5 kg
k = 60 N/m
x = 3 m
v = 4 m/s

## Homework Equations

d²x/dt² + (k/m)*x = 0

## The Attempt at a Solution

I solved the differential equation using DSolve and plotted the resulting function, ok. But what if there was friction? I have no idea how I'd plot that graph.

And sorry for my bad english. D:

Related Introductory Physics Homework Help News on Phys.org
ehild
Homework Helper
Friction would change the differential equation. If the object slides on a horizontal surface, the force of friction is constant in magnitude, but opposite to velocity, v=dx/dt.
It is also possible that "friction" means some resistive force and is proportional to the velocity, and opposite to it. Then the equation will be

d²x/dt² + (k/m)*x +γ/m dx/dt= 0, the equation of a damped harmonic oscillator.

ehild

It worked, but I still don't get it. I thought friction was independent of velocity, so what is this "friction"?

ehild
Homework Helper
You did not specify the kind of friction and its value.

Sliding friction is independent of the magnitude of velocity, but depends on its sign - it is opposite to the velocity v. Fr=-μg sgn(v).
So you have to solve the equation

d²x/dt² + (k/m)*x +μg/m*sgn(dx/dt)= 0

with the condition that both x(t) and dx/dt are continuous.
An example is shown here: http://www.wolframalpha.com/input/?i=x"+x+0.1sgn(x')=0

ehild

Last edited:
Thanks, I understand it now, but when I try to solve this equation using Mathematica nothing happens. The program sends back to me the same thing I typed and no error messages.

ehild
Homework Helper
The solution is "piecewise" and the "pieces" depend very much on the parameters and initial conditions. There is no solution in a closed form.
Wolframalpha did not work with the general equation, either.
Try to give Mathematica the equation with numerical parameters and initial conditions and see if it does anything.

ehild

This is what I'm doing:

m := 0.5(* kg *)
k := 60(* N/m *)
μ := 0.4
g := 10(* m/s² *)
DSolve[{x''[t] + (k/m)*x[t] + μ*g*Sign[x'[t]] == 0, x == 3,
x' == 4}, x[t], t]

ehild
Homework Helper
It is a complicated problem, and Mathematica might not be able to handle it.

ehild

vela
Staff Emeritus
Homework Helper
You could try using NDSolve to get a numerical solution.

gabbagabbahey
Homework Helper
Gold Member
This is what I'm doing:

m := 0.5(* kg *)
k := 60(* N/m *)
μ := 0.4
g := 10(* m/s² *)
DSolve[{x''[t] + (k/m)*x[t] + μ*g*Sign[x'[t]] == 0, x == 3,
x' == 4}, x[t], t]
Mathematica can't solve this analytically, that's why it spits out exactly what you put into it. You can probably get a numerical solution with NDSolve (It's been a while since I've used mathematica, but I think that is what it is called).

A more typical setup (as far as nice analytical solutions go) is a velocity dependant damping (such as from air resitance).

Thanks guys, I'll just use the other equation.

ehild
Homework Helper
The equation d²x/dt² + (k/m)*x +μg/m*sgn(dx/dt)= 0
I suggested in #4 is not quite correct. The sign function returns zero for v=0, but the force of friction is not zero. But it is static friction. Assuming that static and kinetic frictions are the same, the direction of friction is opposite to x(t) when v=0.

It has to be checked at every turning point if the elastic force is enough to overcome friction, that is |x|>μg/k

So the equation

d²x/dt² + (k/m)*x +μg/m*sgn(dx/dt)= 0

has to be solved according to the initial conditions, but the solution is valid for 0<t<t1, where v(t1)=0.
Check if |x(t1)|>μg/k.
In the next step, the initial conditions are x(t1) and v(t1)=0, with opposite sign for the friction. It goes on till v reaches zero again...

ehild

Thanks again. :)