I've been trying to figure this out for a few hours now and it's driving me nuts. I am trying to confirm that, after transforming a Schrodinger equation, that the new wavefunctions satisfy the new potential.
In pseudocode, I'm trying to do something like this (Here I use a Hermite Polynomial / Harmonic Oscillator Example):
(*For the mth transformation, here let m=0*)
m = 0
(*Define the wavefunction*)
wavefunction[x_,n_]:= (-1)^n*Exp[1/4 x^2]*D[Exp[-1/2 x^2], {x, n}]
(*Define the potential*)
potential[x_] := 1/4 x^2
(*Define the energy eigenvalues*)
energy[n_] := n + 1/2
(*Call a function to check if the first m+10 eigenvalues work*)
ConfirmSolution[wavefunction[x, n], potential[x], energy[n], m]
(*When called, the function will return TRUE or FALSE when evaluated*)
(*Somewhere in my code, the following function exists: *)
Confirm[wavefunction[x, n], potential[x], energy[n], m] :=
For[i = 0, i <= m + 10, i++,
If[FullSimplify[-D[wavefunction[x, i], {x, 2}] + potential[x]*wavefunction[x, i]] != FullSimplify[energy[i]*wavefunction[x, i]],
(*If the Schrodinger equation is not true for ANY eigenstate 'i'*)
(*Return FALSE*)
(*Exit the function call immediately to save computation time*)
];
]:
(*If for all states 0...m+10 the Schrodinger equation is satisfied*)
(*Return TRUE*)
]
I know that I should be able to figure this out by googling it, but I'm not having any luck. Haha
So in Tex, to clarify this... it would look like:
$\psi_{n}(x) = (-1)^{n}e^{\frac{1}{4} x^{2}} \dfrac{d^{n}}{dx^{n}} ( e^{- \frac{1}{2} x^{2}} )$
$V(x) = \dfrac{1}{4} x^{2}$
$E_{n}(x) = n + \dfrac{1}{2}$
Then we would check to see if it satisfies the Schrodinger Equation for state $0$
$LHS = - \dfrac{d^{2}}{dx^{2}} \left( (-1)^{n}e^{\frac{1}{4} x^{2}} \dfrac{d^{n}}{dx^{n}} ( e^{- \frac{1}{2} x^{2}} ) \right) + \left( \dfrac{1}{4} x^{2} \right) \left( (-1)^{n}e^{\frac{1}{4} x^{2}} \dfrac{d^{n}}{dx^{n}} ( e^{- \frac{1}{2} x^{2}} ) \right) \bigg|_{n=0}$
$ = \left( \dfrac{1}{2} \right) \left( e^{- \frac{1}{4} x^{2}} \right) $
and
$ RHS = \left( n + \dfrac{1}{2} \right) \left( (-1)^{n}e^{\frac{1}{4} x^{2}} \dfrac{d^{n}}{dx^{n}} ( e^{- \frac{1}{2} x^{2}} ) \right) \bigg|_{n=0} $
$ = \left( \dfrac{1}{2} \right) \left( e^{- \frac{1}{4} x^{2}} \right) $
So for $n=0$, $LHS = RHS$.
Then we would check to see if it satisfies the Schrodinger Equation for state $1$... then $2$... etc... and if it is satisfied for all states from $0 \rightarrow m+10$, then it would return $TRUE$. However, if for any of the states it $LHS \neq RHS$, then it would immediately abort the method call and return $FALSE$.
EDIT: Thanks for the help! I think I've almost got it. Would the following function work?
checksol[psi_, u_, e_, m_] := Module[{LHS, RHS, x},
res = True;
For[i = 0, i <= m + 10, i++,
LHS = -D[psi[x, i], {x, 2}] + v[x]*(psi[x, i]);
RHS = e[i]*(psi[x, i]);
res = TrueQ[FullSimplify[LHS - RHS] == 0];
If[Not[res], Print["Failed on eigenstate: " <> ToString[i]]; Break[]]
];
res
]
I believe that this would return True or False for all intended cases (or at least I can't seem to get it to return anything unexpected for everything I've tried so far).
I'm wondering if there is a problem defining res=True right away on the off chance that the for loop doesn't make it through the first iteration... But it would crash if that happened would it not? Would it be wise to put the for loop in a try/catch statement?
I was reading and saw that TrueQ may be a poor choice here, but I'm only concerned with the equation to be true within the entire domain of x. Is there a way to specify: check to see if the solution is true for all values of x within the domain x in (a,b)?
I did confirm that this does break out as soon as it fails, and now displays which eigenvalue it fails on.
Confirm[wavefunction[x_, n_], potential[x_], energy[n_]]
in any of the languages you mentioned? It's hard to answer your question with the information you gave, could you provide a minimal example which will show your problem? My guess is that you did make definitions forwavefunction
,potential
andenergy
and because these are evaluated the definition ofConfirm
can never match as the results of the former will not have theHead
s you are trying to match anymore... $\endgroup$ – Albert Retey Jun 12 '15 at 20:51