3
$\begingroup$

I'm using Mathematica 9 to try to manipulate a 3D plot. My code is:

Clear[f, α, n]
n = 0;
f = (1/Pi)*(-1)^n*Exp[-2*H/h]*LaguerreL[n, 4 H/h] - (2/3)*α*
p^3*D[(1/Pi)*(-1)^n*Exp[-2*H/h]*LaguerreL[n, 4 H/h], p, 
p] - (1/3)*α*p^2*
D[(1/Pi)*(-1)^n*Exp[-2*H/h]*LaguerreL[n, 4 H/h], 
p] + (1/2)*α^2*((39/9)*p^4*
  D[(1/Pi)*(-1)^n*Exp[-2*H/h]*LaguerreL[n, 4 H/h], p, p] + (28/9)*
  p^5*D[(1/Pi)*(-1)^n*Exp[-2*H/h]*LaguerreL[n, 4 H/h], p, p, 
   p] + (4/9)*p^6*
  D[(1/Pi)*(-1)^n*Exp[-2*H/h]*LaguerreL[n, 4 H/h], p, p, p, 
   p] + (6/9)*p^3*
  D[(1/Pi)*(-1)^n*Exp[-2*H/h]*LaguerreL[n, 4 H/h], p])
Manipulate[Plot3D[f, {x, -10, 10}, {p, -10, 10}, PlotPoints -> 200, PlotRange -> All], {α, 0, 1, 1}]

where $h=1$ and $H=\frac{1}{2}(x^2+p^2)$.

This, however, just gives a blank plot.

enter image description here

Evaluating the function manually, I find that it is equal to:

$\frac{e^{-p^2-x^2}}{\pi }-\frac{1}{3} 2 \alpha p^3 \left(\frac{4 p^2 e^{-p^2-x^2}}{\pi }-\frac{2 e^{-p^2-x^2}}{\pi }\right)+\frac{2 \alpha p^3 e^{-p^2-x^2}}{3 \pi }+\frac{1}{2} \alpha ^2 \left(\frac{13}{3} p^4 \left(\frac{4 p^2 e^{-p^2-x^2}}{\pi }-\frac{2 e^{-p^2-x^2}}{\pi }\right)-\frac{4 p^4 e^{-p^2-x^2}}{3 \pi }+\frac{4}{9} p^6 \left(-\frac{48 p^2 e^{-p^2-x^2}}{\pi }+\frac{12 e^{-p^2-x^2}}{\pi }+\frac{16 p^4 e^{-p^2-x^2}}{\pi }\right)+\frac{28}{9} p^5 \left(\frac{12 p e^{-p^2-x^2}}{\pi }-\frac{8 p^3 e^{-p^2-x^2}}{\pi }\right)\right)$

In Manipulate, if I manually replace f with this function, I get exactly what I want.

Manipulate[ Plot3D[E^(-p^2 - x^2)/π -    2/3 p^3 (-((2 E^(-p^2 - x^2))/π) + (
  4 E^(-p^2 - x^2) p^2)/π) α + (   2 E^(-p^2 - x^2) p^3 α)/(3 π) + 1/2 (13/3 p^4 (-((2 E^(-p^2 - x^2))/π) + (         4 E^(-p^2 - x^2) p^2)/π) + 
  28/9 p^5 ((12 E^(-p^2 - x^2) p)/π - (         8 E^(-p^2 - x^2) p^3)/π) + 
  4/9 p^6 ((12 E^(-p^2 - x^2))/π - (         48 E^(-p^2 - x^2) p^2)/π + (         16 E^(-p^2 - x^2) p^4)/π) - (4 E^(-p^2 - x^2) p^4)/(      3 π)) α^2, {x, -10, 10}, {p, -10, 10},   PlotPoints -> 200, PlotRange -> All], {α, 0, 1, 1}]

enter image description here

Does anyone know why this difference occurs? How would I bypass this so that my first piece of code will work, that is, without having to manually input f i.e. get my second image as an output using my first piece of code? My goal is to be able to have Manipulate control the values of both n and $\alpha$.

Thanks

$\endgroup$
0

1 Answer 1

4
$\begingroup$

The α used ouside of the Manipulate is not the same as the α inside of the Manipulate (scoping). Parameterize f to make the variables identical. Excessive PlotPoints slows the plotting.

Clear[f, α]
n = 0;
h = 1;
H = (x^2 + p^2)/2;
f[α_, x_, p_] = 
  (1/Pi)*(-1)^n*Exp[-2*H/h]*LaguerreL[n, 4 H/h] - (2/3)*α*p^3*
     D[(1/Pi)*(-1)^n*Exp[-2*H/h]*LaguerreL[n, 4 H/h], p, p] - (1/3)*α*
     p^2*D[(1/Pi)*(-1)^n*Exp[-2*H/h]*LaguerreL[n, 4 H/h], 
      p] + (1/2)*α^2*((39/9)*p^4*
        D[(1/Pi)*(-1)^n*Exp[-2*H/h]*LaguerreL[n, 4 H/h], p, p] + (28/9)*p^5*
        D[(1/Pi)*(-1)^n*Exp[-2*H/h]*LaguerreL[n, 4 H/h], p, p, p] + (4/9)*p^6*
        D[(1/Pi)*(-1)^n*Exp[-2*H/h]*LaguerreL[n, 4 H/h], p, p, p, p] + (6/9)*
        p^3*D[(1/Pi)*(-1)^n*Exp[-2*H/h]*LaguerreL[n, 4 H/h], p]) // Simplify;
Manipulate[
 Plot3D[f[α, x, p],
  {x, -10, 10}, {p, -10, 10},
  PlotPoints -> 51,
  PlotRange -> All],
 {α, {0, 1}, ControlType -> SetterBar},
 SynchronousUpdating -> False]

enter image description here

$\endgroup$
1
  • $\begingroup$ One can use PlotPoints -> ControlActive[15, 200], and adjust to get the right balance of responsiveness and quality -- 200 may be needlessly large in any case. MaxRecursion may be a better option to play with. One doesn't need all those extra points where the terrain is flat. $\endgroup$
    – Michael E2
    Jul 29, 2014 at 4:05

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