Coupled Springs

2 masses / 3 springs

Here is a function to draw our two mass, three spring problem.
Evaluating the cell below should get you the picture above.

state2[x_,y_,L_:12]:= Graphics[{Disk[{0,0},.2],Disk[{L,0},.2],ParametricPlot[{0+(t*x),Sin[2 Pi 6 t]},{t,0,1},Axes->True,PlotStyle->Red,PlotRange->{{0,L},{-1,1}}][[1]],Rectangle[{x-1/4,-1/4},{x+1/4,1/4}],
ParametricPlot[{x+t*(y-x),Sin[2 Pi 6 t]},{t,0,1},PlotStyle->Blue][[1]],
Rectangle[{y-1/4,-1/4},{y+1/4,1/4}],
ParametricPlot[{y+t*(L-y),Sin[2 Pi 6 t]},{t,0,1},PlotStyle->Orange][[1]]}]
state2[4,8]

Here are the F=ma equations for our two mass problem.  Make sure you understand the signs etc.
Notice we clear the definitions of x1 etc., since we may have used that symbol above.

x1[t_] = .;x2[t_]=.;  (* It's OK if this complains that x1 is not defined *)
eq1 = m1 x1''[t]  == -(k1+k2)  x1[t] + k2 x2[t]
eq2 = m2 x2''[t]  ==  +k2 x1[t] - (k2+k3) x2[t]

Start with the simplest case, with identical masses and springs:

p1= {k1->1,k2->1,k3->1,m1->1,m2->1}
{eq1,eq2}/.p1 //MatrixForm

Let's solve with certain boundary conditions and solve for the motion and then animate:

s=DSolve[{eq1,eq2,x1[0]==1,x2[0]==0,x1'[0]==0,x2'[0]==0}/.p1,{x1[t],x2[t]},t]
(y1[t_]=x1[t]/.s[[1]];
y2[t_] = x2[t]/.s[[1]];
Animate[state2[4+y1[t],8+y2[t]],{t,0,40}])

Tweak #1--change one of the masses

Morin 4.9 (solved in the book) asks about the 2 mass case where m1 = m and m2 = 2 m.
We modify the parameter choice p2 accordingly, and express the coupling matrix.

p2= {k1->1,k2->1,k3->1,m1->1,m2->2}
(m = {{-(k1+k2)/m1,k2/m1},{k2/m2,-(k2+k3)/m2}}/.p2) // MatrixForm

Next DSolve, choose initial conditions and Animate:

s=DSolve[{eq1,eq2,x1[0]==-1,x2[0]==1,x1'[0]==0,x2'[0]==0}/.p2,{x1[t],x2[t]},t];
FullSimplify[s,Assumptions->t>0]
(y1[t_]=x1[t]/.s[[1]];
y2[t_] = x2[t]/.s[[1]];
Animate[state2[4+y1[t],8+y2[t]],{t,0,40}])

Tweak #2--more masses

Now add a third mass.  As before we write the equations for three coordinates, NDSolve, and animate with:

state3[x_,y_,z_,L_:12]:= Graphics[{Disk[{0,0},.2],Disk[{L,0},.2],
ParametricPlot[{0+(t*x),Sin[2 Pi 6 t]},{t,0,1},Axes->True,PlotStyle->Red][[1]],
Rectangle[{x-1/4,-1/4},{x+1/4,1/4}],
ParametricPlot[{x+t*(y-x),Sin[2 Pi 6 t]},{t,0,1},PlotStyle->Blue][[1]],
Rectangle[{y-1/4,-1/4},{y+1/4,1/4}],
ParametricPlot[{y+t*(z-y),Sin[2 Pi 6 t]},{t,0,1},PlotStyle->Orange][[1]],
Rectangle[{z-1/4,-1/4},{z+1/4,1/4}],
ParametricPlot[{z+t*(L-z),Sin[2 Pi 6 t]},{t,0,1},PlotStyle->Green][[1]]},PlotRange->{{-1/4,L+1/4},{-1,1}}]

eq1 = m1 x1''[t]  == -(k1+k2)  x1[t] + k2 x2[t]
eq2 = m2 x2''[t]  ==  +k2 x1[t] - (k2+k3) x2[t] + k3 x3[t]
eq3 = m3 x3''[t] == k3 x2[t] - (k3+k4) x3[t]

Start with the simplest case, with identical masses and springs:

p4= {k1->1,k2->1,k3->1,k4->1,m1->1,m2->1,m3->1}
system=({eq1,eq2,eq3,x1[0]==1,x2[0]==0,x3[0]==0,x1'[0]==0,x2'[0]==0,x3'[0]==0}/.p4)
s=NDSolve[system,{x1[t],x2[t],x3[t]},{t,0,50}] (* Solve numerically ! -- Regular old DSolve is too slow *)
s4 = FullSimplify[s[[1]]]

y1[t_]=x1[t]/. s4
y2[t_] = x2[t]/.s4
y3[t_] = x3[t]/.s4
Animate[state3[3+y1[t],6+y2[t],9+y3[t]],{t,0,50}]

The eigenvalue problem

In the spring problems which follow there is always a matrix, and we are interested in the eigenvectors.
Here is a way to visualize them.  Come back and change the matrix as appropriate.

$Post=MatrixForm
mat = {{2,-1},{-1,2}}
vplot=VectorPlot[mat.{x,y},{x,-1,1},{y,-1,1}]

Here is a widget to see the input and output as your matrix acts on a vector:

Manipulate[Show[Graphics[{{Red,Arrow[{{0,0},{Cos[θ],Sin[θ]}}]},{Blue,Arrow[{{0,0},mat.{Cos[θ],Sin[θ]}}]}}],PlotRange->{{-3,3},{-3,3}}],{{θ,0},-2π,2π}]

Here is how to ask for the eigenvectors and eigenvalues,  and then draw them on top of the plot above:

Eigensystem[mat]
Show[vplot,Graphics[{
{Red,  Arrow[{{0,0},Eigenvectors[mat][[1]]}]},{Blue,Arrow[{{0,0},Eigenvectors[mat][[2]]}]}
}]]