I'm finding eigenfunctions using NDEigensystem of various hamiltonians. For example, the hamiltonian with Shcrödinger's equation: $$ H u(x)=-\hbar^2 u''(x) + A x^2 u(x). $$ I would like to be able to vary parameters in the Hamiltonian using sliders and see the corresponding changes in the plots of the eigenfunctions. I'm quite new to Mathematica and have so far tried this:

  schrod[x_, \[HBar]_, A_] := -\[HBar]^2*u''[x] + A*x^2*u[x];

{vals, funs} = 
  NDEigensystem [schrod, u[x], {x, -2 \[Pi], 2 \[Pi]}, 8];
fun2 = funs[[2]];
 Plot[Evaluate[Abs[fun2^2]], {x, -2 \[Pi], 2 \[Pi]}, 
  PlotRange -> Automatic], {x, -2 \[Pi], 2 \[Pi]}, {\[HBar], 0, 
  1}, {A, 0, 10}] 

There a couple of typos in your expression. You define schrod as a function but then you call it without arguments. There is no need to vary $\hbar$ and $A$ independently since you can rescale one into the other by changing the unit of time. Also $x$ is not variable of the Manipulate since it is used by the Plot.

Something like this would work

schrod[x_, A_] := -u''[x] + A*x^2*u[x];

Clear[vals, funs];
fun2[A_] := NDEigensystem[schrod[x,  A], u[x], {x, -2π, 2π}, 2][[2,2]];

Manipulate[ Plot[Evaluate[Abs[fun2[A]^2]], {x, -2 π, 2π}], {A, 0, 10}]

enter image description here

You can make it a bit more fun while varying the eigenfunction as well:

fun[A_, n_] := NDEigensystem[schrod[x, 1, A], u[x], {x,-2π,2 π}, n][[2, n]];

 Plot[Evaluate[Abs[fun[A, n]^2]], {x, -2π, 2 π}], {A, 0, 10}
 , {n, 2, 4, 1}]

enter image description here

  • 1
    $\begingroup$ It might be helpful to the OP, seeing as they are new, if you noted what differs, syntactically, between your example and their’s. I can comment this to them if you’d find that may be a better route to take! $\endgroup$ – CA Trevillian Jul 6 '20 at 16:59

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.