2

I am bothered by the output format of the last two elements of efre. Is there a way to make these two look like the same format as the first two in efre?

Remove["Global`*"]

coe = k/m SparseArray[{{i_, i_} -> -2, {i_, j_} /; Abs[i - j] == 1 -> 
      1} , {4, 4}];
efre = Sqrt[-coe // Eigenvalues] // Simplify 
evec = coe // Eigenvectors // Simplify;
Column[Subscript[ω, #] & /@ Range@4 == efre // Thread, 
 Spacings -> 2]

enter image description here

Dr. belisarius
  • 115,881
  • 13
  • 203
  • 453
Lawerance
  • 517
  • 3
  • 13

2 Answers2

4

As Bob Hanlon comments the original output without Simplify is already in the form you want:

efre = Sqrt[-coe // Eigenvalues]
{Sqrt[1/2 (5 + Sqrt[5])] Sqrt[k/m],
 Sqrt[1/2 (3 + Sqrt[5])] Sqrt[k/m], 
 Sqrt[1/2 (5 - Sqrt[5])] Sqrt[k/m],
 Sqrt[1/2 (3 - Sqrt[5])] Sqrt[k/m]}

However, it may help to understand how to work with Simplify and FullSimplify.
As elsewhere(1),(2) you need to specify a ComplexityFunction that is closer to the way you see expressions rather than Mathematica's internal one, which is roughly approximated by LeafCount.

For the sake of an example let's transform our output into a different form so that we can see that Simplify has an effect:

e2 = ExpandAll //@ efre
{Sqrt[5/2 + Sqrt[5]/2] Sqrt[k/m], 
 Sqrt[3/2 + Sqrt[5]/2] Sqrt[k/m],
 Sqrt[(5 k)/m - (Sqrt[5] k)/m]/Sqrt[2],
 Sqrt[(3 k)/m - (Sqrt[5] k)/m]/Sqrt[2]}

Now we Simplify with a ComplexityFunction that is based on visual output size:

Simplify[e2, ComplexityFunction -> Composition[StringLength, ToString]]
{Sqrt[1/2 (5 + Sqrt[5])] Sqrt[k/m],
 Sqrt[1/2 (3 + Sqrt[5])] Sqrt[k/m], 
 Sqrt[1/2 (5 - Sqrt[5])] Sqrt[k/m],
 Sqrt[1/2 (3 - Sqrt[5])] Sqrt[k/m]}
Mr.Wizard
  • 271,378
  • 34
  • 587
  • 1,371
2
Remove["Global`*"]

coe = k/m SparseArray[{{i_, i_} -> -2, {i_, j_} /; Abs[i - j] == 1 -> 
      1}, {4, 4}];
efre = Sqrt[k/m] *Simplify[Sqrt[-coe // Eigenvalues]/Sqrt[k/m]];
evec = coe // Eigenvectors // Simplify;
Column[Subscript[\[Omega], #] & /@ Range@4 == efre // Thread, 
 Spacings -> 2]

enter image description here

Bob Hanlon
  • 157,611
  • 7
  • 77
  • 198