2
$\begingroup$

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

$\endgroup$
  • $\begingroup$ Replace // Simplify with //N// Simplify and they look the same. $\endgroup$ – bill s Jul 27 '14 at 1:09
  • $\begingroup$ @bills Your way somehow works, but what I want is a symbolic expression not the numerical one. $\endgroup$ – Lawerance Jul 27 '14 at 1:12
2
$\begingroup$
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

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.