I have created a program to solve any system of three springs and two masses using Mathematica's Eigendecomposition functions. My goal is to solve a generalization of the spring system presented in the book Mathematical Methods in the Physical Sciences, 3rd Edition by Mary L. Boas on page 185 on the section on applications of diagonalization.
Here is what I have so far.
GetCoefficients[k1_, k2_, k3_] :=
Coefficient[Expand[k1*x^2 + k2*(x - y)^2 + k3*y^2], #] & /@ {x^2,
x y, y^2}
SpringFunction[k1_, k2_, k3_, m1_, m2_] :=
Module[{PotentialEnergyMatrix = {{GetCoefficients[k1, k2, k3][[1]],
GetCoefficients[k1, k2, k3][[2]]/
2}, {GetCoefficients[k1, k2, k3][[2]]/2,
GetCoefficients[k1, k2, k3][[3]]}},
KineticEnergyMatrix = {{m1, 0}, {0, m2}}}, <|
"Potential Energy V" -> Expand[k1*x^2 + k2*(x - y)^2 + k3*y^2],
"Kinetic Energy Matrix T" -> MatrixForm@KineticEnergyMatrix,
"V matrix" -> MatrixForm@PotentialEnergyMatrix,
"\!\(\*SuperscriptBox[\(T\), \(-1\)]\)V" ->
MatrixForm[Inverse@KineticEnergyMatrix . PotentialEnergyMatrix],
"Eigenvalues" ->
Eigenvalues[Inverse@KineticEnergyMatrix . PotentialEnergyMatrix],
"Eigenvectors" ->
MatrixForm@
Eigenvectors[
Inverse@KineticEnergyMatrix . PotentialEnergyMatrix],
"\[Lambda]" ->
"m*\!\(\*FractionBox[SuperscriptBox[\(\[Omega]\), \(2\)], \
\(k\)]\)",
"\!\(\*SubscriptBox[\(\[Omega]\), \(1\)]\)" -> \[Sqrt](1/m k*
Eigenvalues[
Inverse@KineticEnergyMatrix . PotentialEnergyMatrix][[1]]),
"\!\(\*SubscriptBox[\(\[Omega]\), \(2\)]\)" -> \[Sqrt](1/m k*
Eigenvalues[
Inverse@KineticEnergyMatrix . PotentialEnergyMatrix][[2]])|>]
For the same code in a Mathematica notebook, see Mathematica Cloud Notebook
My goal is the following:
expand it to any number of springs and masses. For example, if the user wanted to enter 7 springs and 6 masses.
Make a function that shows steps



mandkin Hugh’s code, following the well-written procedure they have laid out. – CA Trevillian Nov 13 '21 at 00:18