Animated Behavior of an
Un-forced Damped Linear Spring

by
K. D.  Stroyan
University of Iowa

copyright 1997 by Academic Press, Inc. - All rights reserved.

Special Mathematica Functions used in this NoteBook

Off[General::spell];
Off[General::spell1];
Off[InterpolatingFunction::dmval];
Off[ParametricPlot::pptr];
Off[Graphics::gprim];
Off[Graphics::gptn];
Off[NDSolve::ndsz];

Needs["Graphics`Colors`"]
	
spring[f_,{y_,t_},{xi_,vi_},tFinal_,dt_,opns___] :=
 Module[{soln,ptt,pt,pt0,seg,crv,tt,x,z,stretch},
soln =Flatten[Map[
	NDSolve[{x[0]==0, y[0]==#[[1]],z[0]==#[[2]],
	x'[t] == 1,y'[t] == z[t], z'[t]== f[y[t],z[t]]},
	{x[t],y[t],z[t]},{t,0,tFinal}]&,
										{{xi,vi}}],1];
											
pt[tt_] := Map[Graphics[{Blue,AbsolutePointSize[5],Point[{tFinal,#}]}]&,
y[t]/.soln/.t->tt];

pt0[tt_] := Map[Graphics[{Blue,AbsolutePointSize[5],Point[{0,#}]}]&,
y[t]/.soln/.t->tt];

ptt[tt_] := Map[Graphics[{Blue,AbsolutePointSize[4],Point[{#[[1]],#[[2]]}]}]&,
{x[t],y[t]}/.soln/.t->tt];

seg[tt_] := Map[Graphics[{Green,Line[{{#[[1]],#[[2]]},{tFinal,#[[2]]}}]}]&,
{x[t],y[t]}/.soln/.t->tt];

stretch[tt_] := Map[Graphics[{Red,AbsoluteThickness[5/(1+2Abs[(#-xi)])],
Line[{{tFinal,xi},{tFinal,#}}]}]&,
y[t]/.soln/.t->tt];
										
crv[tt_] := Plot[Evaluate[y[t]/.soln],{t,0,tt},opns,
			AspectRatio->1,DisplayFunction->Identity];
			
Show[{crv[dt/100],pt[0],pt0[0],seg[0]},opns,
PlotRange->{{0,10},{0,10}},AspectRatio->1,
DisplayFunction->$DisplayFunction];
Do[Show[{crv[tt],pt[tt],ptt[tt],seg[tt],stretch[tt]},DisplayFunction->$DisplayFunction];,
{tt,dt,tFinal,dt}];
	Return[soln];	
];

Notebook Overview

This NoteBook shows how an object suspended from a spring oscillates after being released with no other forces applied other than the ones required to place it in its starting position.  The linear constant coefficient autonomous differential equation

m y" + c y' + s y == 0

with initial conditions

y[0] == yi 
	y'[0] == vi

describes the motion of a mass m  on a spring (s) with a shock absorber (c).  This program animates the motion and plots the solution.

Note: This can also be written in the "phase variable" form
			y' = z
			z' = -s y/m - c z/m			
			y(0) = yi
			z(0) = vi

References to the Text

This NoteBook goes with Chapter 23 of the text.

Combined Computation

Clear[y, z, t, f]; f[y_, z_] := -((s y)/m) - ((c z)/m)m = 0.5; c = 0.1; s = 1.0; yi = 1.0; vi = 1.0; tFinal = 15; dt = 0.25; spring[f, {y, t}, {yi, vi}, tFinal, dt, 
      PlotRange -> {{0, tFinal + dt}, {-1, 1.3}}];

Exercises

Problem 23.3 Your Car's Worn Shocks

What is the algebraic condition between the physical paramteres  m, c, s of the spring equation

m x''[t] + c x'[t] + s x[t] == 0

that determines whether or not your car oscillates after it hits a bump?

Make a spring animation to show what happens to the solutions with

m = s = x'[0] = 1
	x[0] = 0
and various values of c, say
	c = 3.0, 2.5, 2.0, 1.5, 1.0, 0.0.