1
$\begingroup$

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]
$\endgroup$
1
$\begingroup$

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[].

| improve this answer | |
$\endgroup$
1
$\begingroup$

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
]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – ForPhysics Jul 22 '14 at 20:11
  • $\begingroup$ 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. $\endgroup$ – ForPhysics Jul 22 '14 at 20:19
  • $\begingroup$ @ForPhysics I just thought have to compute eigenvalues each time could slow things down. $\endgroup$ – Chip Hurst Jul 22 '14 at 20:39

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.