# Inconsistency of output format in Eigenvalue

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]


-
Replace // Simplify  with //N// Simplify  and they look the same. – bill s Jul 27 '14 at 1:09
@bills Your way somehow works, but what I want is a symbolic expression not the numerical one. – Lawerance Jul 27 '14 at 1:12

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]


-
I guess this is the only way, although it looks a little bit weird. – Lawerance Jul 27 '14 at 2:58
@Lawrence - You can also just leave off the Simplify when defining efre: efre = Sqrt[-coe // Eigenvalues] – Bob Hanlon Jul 27 '14 at 3:13
Thanks a lot! That's what I was looking for! – Lawerance Jul 27 '14 at 3:15

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]}

-
Since you love terse code how about the infix form of Composition (@*) introduced in V10 – RunnyKine Jul 27 '14 at 11:38
@RunnyKine I almost used that but out of sympathy for users of old versions I did not. Good note however. – Mr.Wizard Jul 27 '14 at 12:13
@Mr.Wizard Great illustrations, thanks! (still reading the document to fully understand these applicaitons) – Lawerance Jul 27 '14 at 20:45