"Solution of non-flat square well with Mathieu functions"

"Units: hbar=m=1, a=pi, so the box is width pi"
"The unpertubed energies are e_n=n^2/2"

"Units: hbar=m=1, a=pi, so the box is width pi"

"The perturbation is the one in the lecture which in these units is"

"lambda Cos[2x] where  lambda=W/2E_1"

e[n_]:=n^2/2

e11[lambda_]:=e[1]-lambda/2

e12[lambda_]:=e11[lambda]-lambda^2/16

e13[lambda_]:=e12[lambda]+lambda^3/128

u[n_,x_]:=Sqrt[2/Pi] Sin[n x]

u11[lambda_,x_]:=u[1,x]-(lambda/8)u[3,x]

norm[lambda_]:=Sqrt[Pi/2]/NIntegrate[Sin[x] MathieuS[MathieuCharacteristicB[1,lambda],lambda,x],{x,0,Pi}]

uexact[lambda_,x_]:=MathieuS[MathieuCharacteristicB[1,lambda],lambda,x] norm[lambda]

NIntegrate[u[1,x]uexact[1,x],{x,0,Pi}]-1.

Plot[{e11[lambda]/e[1],e12[lambda]/e[1],e13[lambda]/e[1],MathieuCharacteristicB[1,lambda]},{lambda,0,3},
AxesOrigin->{0,0},
PlotStyle->{Red,Green,Blue,Black}]

Manipulate[Plot[{u11[lambda,x],uexact[lambda,x]},
{x,0,Pi},PlotRange->{0,Sqrt[2/Pi](1+lambda/8)},
PlotStyle->{Red,Black},AxesLabel->{"x Pi/a","E1/E10"},Ticks->{{0,Pi/2,Pi},None},PlotLabel->u11[x]],
{lambda,0,3}]