Message Boards Message Boards

Manipulate causes kernel crash and graphic errors with SphericalPlot3D? M10

Posted 8 years ago

Hi everyone, recently I have started plotting hydrogen's molecular orbitals with Mathematica 10.2 using SphericalPlot3D over sperical harmonics. Everything was going well, till I decided to use the function Manipulate to avoid changing every time by hand values of n, m and l (quantum numbers). At first, when I press enter and the computation ends, everything looks great, but if I try to modify one of the three quantum numbers, via the slider bars aside, the plot fills with irregular lines (like a super low resolution 3d model) and Mathematica stops working. I really can't figure out what the problem may be, since without using Manipulate to plot the orbitals, every combination of n, l, m, returns a perfect graph. Down below it's reported the source code I'm using and a screenshot regarding the corrupted plot.

Manipulate[
 Y[\[Theta]_, \[Phi]_] := 
  1/Sqrt[2] (SphericalHarmonicY[l, m, \[Theta], \[Phi]] + 
     SphericalHarmonicY[l, -m, \[Theta], \[Phi]]);
 SphericalPlot3D[
  Y[\[Theta], \[Phi]]^2, {\[Theta], -Pi, Pi}, {\[Phi], -Pi, Pi}, 
  PlotRange -> Full, ImageSize -> {400, 400}, Mesh -> None],
 {{n, 3, "n"}, 1, 5, 1, ImageSize -> Small, Appearance -> Labeled},
 {{l, 2, "l"}, 0, n - 1, 1, ImageSize -> Small, Appearance -> Labeled},
 {{m, 0, "m"}, -l, l, 1, ImageSize -> Small, Appearance -> Labeled},
 ControlPlacement -> Left]
Attachments:
POSTED BY: Edoardo Ottoni
3 Replies

Hi Edoardo, From experience it's better to define functions outside of the manipulate code. Your variables that change are each time redefing your function (every time with different parameters) which is not efficient. So I keep my functions outside of the manipulate and pass all variables into that function. I'm not an expert so there are probably other ways to do it.

POSTED BY: l van Veen

For me this worked better

Y[\[Theta]_, \[Phi]_, l_, m_, n_] := 1/Sqrt[2] (SphericalHarmonicY[l, m, \[Theta], \[Phi]] +  SphericalHarmonicY[l, -m, \[Theta], \[Phi]]);

Manipulate[
 SphericalPlot3D[
  Y[\[Theta], \[Phi], l, m, n]^2, {\[Theta], -Pi, Pi}, {\[Phi], -Pi, 
   Pi}, PlotRange -> Full, ImageSize -> {400, 400}, 
  Mesh -> None], {{n, 3, "n"}, 1, 5, 1, ImageSize -> Small, 
  Appearance -> Labeled}, {{l, 2, "l"}, 0, n - 1, 1, 
  ImageSize -> Small, Appearance -> Labeled}, {{m, 0, "m"}, -l, l, 1, 
  ImageSize -> Small, Appearance -> Labeled}, 
 ControlPlacement -> Left]
POSTED BY: l van Veen
Posted 8 years ago

Thank you a lot, this new source code solved my problem. Still a bit confused because for me these two methods seems identical.. but apparently not for the program.

POSTED BY: Edoardo Ottoni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract