Square well ground state (Weinberg problem 1.1)

Define the ground state wavefunction in a square well from [-a,a]. Check it’s norm. (Every command is executed in Mathematica using ‘Shift Return’ after it’s typed properly. To input ψ in Mathematica, type ‘esc y esc’)

ψ0[x_] = ...
Integrate[ψ0[x] ψ0[x],{x,-a,a}]

Define the trial wavefunction, up to a constant normalization factor. The underbar _ makes x a variable.

ψ[x_] = norm (a^2-...)

Norm is defined to make the wavefunction normalized

ShouldBeOne = Integrate[...,{x,-a,a}]

Find solutions for norm. (We clear first to avoid problems when you accidentally re-run the command.)

Clear[norm]
sols = Solve[ShouldBeOne==1,norm]

Select positive one

norm = norm /. sols[[2]]

Plot ψ and ψ0 for a=3

Plot[{ψ[x]/.a->3,ψ0[x]/.a->3},{x,-3,3}]

Find the probability that ψ is in the ground state by calculating the overlap of the two wavefunctions. Numerical evaluation of ‘blah’ can be done by N[blah] or by blah // N.

Overlap = Integrate[..., {x, -a, a}]
ProbGroundState = ... //N