# Eigenvectors inside a maniupulate function

I am trying to make a physics application and it requires that the eigenvectors be taken for a 3x3 matrix. It is my intention that Mathematica never have to deal with the matrices symbolically. Therefore, because the element I am plotting by is in the matrices, I have used set delay in my code to make sure that when the functions are called all parameters have numerical values. Nonetheless, Mathematica continuous to return the error that not all the eigenvectors can be found though I have SynchronousUpdating -> False, and what I also find strange is that having a set delay inside the manipulate function causes the application to continuously update even when nothing is changing. The code below is a simplified case of how the code runs. Does anyone have ideas to how to make this code run so that it is not continuously updating and athematica never has to deal with things symbolically.

 Manipulate[
g[e_] := ( {
{e, ρ, 11},
{1, e, ρ},
{1, 1, e}} );

U[e_] := (Transpose[Eigenvectors[g[e]]]).( {
{0, 0, 1},
{0, 1, 0},
{1, 0, 0}
} );
LogLinearPlot[(\!$$\*UnderoverscriptBox[\(\[Sum]$$, $$l = 1$$, $$3$$]$$\(U[e]$$[$$[1, l]$$]\)\)), {e, .01, 50},
AxesLabel -> {"Disrance (Km)", "Probability"},
PlotRange -> All], {{ρ, 9.6,
"\!$$\*FractionBox[\(g$$, SuperscriptBox[$$cm$$, $$3$$]]\)"}, 0.,
120.}, ControlPlacement -> Left, SynchronousUpdating -> False,
ContinuousAction -> False]


I would suggest: Try to write your function definition outside of the Manipulate, but in dependence of the changing parameter, like so:

g[ρ_, e_] := ( {{e, ρ, 11}, {1, e, ρ}, {1, 1, e}} );
U[ρ_, e_] := (Transpose[Eigenvectors[g[ρ, e]]]).( { {0, 0, 1}, {0, , 0}, {1, 0, 0}} );


And than inside the Manipulate use this function definition:

Manipulate[ LogLinearPlot[ Sum[U[ρ, e][[1, l]], {l, 1, 3}], {e, .01, 50},
AxesLabel -> {"Distance (Km)", "Probability"},
PlotRange -> All], { {ρ, 9.6,  "\!$$\*FractionBox[\(g$$, SuperscriptBox[$$cm$$, $$3$$]]\)"}, 0., 120.}, ControlPlacement -> Left]


If you only want to get rid of the error message, you can use Quiet[].

You should define your functions outside of the Manipulate so the definitions aren't reevaluated each time the slider is moved. In doing this, you'll need to make g and U explicitly depend on ρ.

g[e_, ρ_] := {
{e, ρ, 11},
{1, e, ρ},
{1, 1, e}
};

U[e_, ρ_] := Transpose[Eigenvectors[g[e, ρ]]] . {
{0, 0, 1},
{0, 1, 0},
{1, 0, 0}
};


Next it would be nice to precompute the sum so the slider will move smoother:

(S[e_, ρ_] := Chop[#])&[Sum[U[e, ρ][[1, l]], {l, 3}]]


Now things should work:

Manipulate[
LogLinearPlot[S[e, ρ], {e, .01, 50},
AxesLabel -> {"Disrance (Km)", "Probability"},
PlotRange -> All
],
{{ρ, 9.6, "\!$$\*FractionBox[\(g$$, SuperscriptBox[$$cm$$, $$3$$]]\)"}, 0., 120.},
ControlPlacement -> Left
] • Yes, that does solve the problem, though I am still curious to why even when I was not moving the slider Mathematica was reevaluating. From what I can tell, a SetDelayed definition causes the Manipulate function to reevaluate nonstop regardless of action. – ForPhysics Jul 22 '14 at 20:11
• Why does defining the Sum S[e,p] outside the Manipulate better the smoothness of the Manipulate. I would think it would have the opposite effect as it simply making mathematica call one more operation. – ForPhysics Jul 22 '14 at 20:19
• @ForPhysics I just thought have to compute eigenvalues each time could slow things down. – Chip Hurst Jul 22 '14 at 20:39