Plot solution of differential equation with conditional constant term

Hi.

I intend to plot a function with a term ‘F’ which is dependant on the value of ‘y’:

m := 1200
k := 300000
b := 25
g := 9.81
F := If[y[t] < -0.4, -m g + 
   Abs[b (-y'[t]) Sqrt[y[t] + 0.4] + k y[t]], -m g]
y''[t_] := F/m
system = DSolve[{y''[t_] := F/m, y[0] == 0, y'[0] == 0}, y, t]
Plot[y[t] /. system, {t, 0, 5}]

The scenario is a falling object which can be modelled as a damper and spring; once it hits the floor then a bouncing force will arise, defined when y=-0.4. I am not sure how to go about this. Thanks for any help!

May be so:

m := 1200
k := 300000
b := 25
g := 9.81
F[t_] := If[y[t] < -0.4, -m g + Abs[b (-y'[t]) *Sqrt[y[t] + 0.4] + k y[t]], -m g]
system = NDSolve[{y''[t] == F[t]/m, y[0] == 1, y'[0] == 0},y, {t, 0, 5}]
Plot[y[t] /. system, {t, 0, 5}]

:slight_smile:

Allright! Thanks mate!

julian, you may also take a quick look of this documentation about event locator method in Mathematica 9.

While “EventLocator” still exists for backward compatibility, starting with Mathematica 9 the recommended tutorial would be

Events and Discontinuities in Differential Equations.

Thanks guys :slight_smile: