Fourier Expansions

Stuff for lecture

Here we turn off some annoying error messages that don't really help much.  Mathematica complains about accuracy problems, but it does just fine.  It's worried about accuracy to one part in (10^12), usually.

Off[NIntegrate::"ploss"]
Off[NIntegrate::"ncvb"];

Moderate width  packet

Below we define a wavefunction in the interval 0 < x < 1.    It is centered at x=0.5, and is normalized.

ψ=(Sqrt[10 (Sqrt[(2/π)])])Exp[-100. (((x-0.5))^2)]
f=NIntegrate[(ψ^2),{x,0,1}]//Chop

Plot[ψ,{x,0,1},PlotRange->All]

Let's calculate the expansion coefficients of this wavefunction in terms of the "particle in a box" states.   First, let's calculate just the coefficient of the first state.  Since we're looking for a number, we can do a numerical integral (NIntegrate) instead of a symbolic one (Integrate).

NIntegrate[(Sqrt[2])ψ Sin[ π x],{x,0,1}]

Now we can calculate a whole set of them, using the Table command.  The Table command will do something repeatedly.

sincoefs=Table[NIntegrate[(Sqrt[2])ψ Sin[ n π x],{x,0,1}],{n,1,20}]

We can get a nicer result if we "Chop" the results, which just round anything below a cutoff ((10^(-10))) to zero.  We then plot them

sincoefs=Chop[Table[NIntegrate[(Sqrt[2])ψ Sin[ n π x],{x,0,1}],{n,1,20}]]

ListPlot[Abs[sincoefs]]

Narrower packet

We repeat the above with a narrower packet:

ψ=(Sqrt[20 (Sqrt[(2/π)])])Exp[-400. (((x-0.5))^2)]
f=NIntegrate[(ψ^2),{x,0,1}]//Chop

Plot[ψ,{x,0,1},PlotRange->All]

sincoefs=Table[NIntegrate[(Sqrt[2])ψ Sin[ n π x],{x,0,1}],{n,1,20}]//Chop

ListPlot[Abs[sincoefs]]

Stuff for homework

Here's our wavefunction:

ψ=(Sqrt[6. (Sqrt[(2/π)])])Exp[-36. (((x-0.5))^2)];

Below we make three lists.  The first is the list of expansion coefficients.  The second is the list of (Subscript[ϕ, n])(x),  and the third is the list of the (Subscript[Φ, n])(x,t).   Note that all of the lists have the same length.

coefs=Table[NIntegrate[ψ   (Sqrt[2 ])Sin[ n π x] , {x,0,1}],{n,1,10}]//Chop
ϕfxns=Table[(Sqrt[2 ]) Sin[n π x]  ,{n,1,10}]
Φfxns=Table[(Sqrt[2 ]) Sin[n π x]  Exp[-I (n^2) t],{n,1,10}]

We can cleverly combine the lists by taking the "dot product" of the two.  Mathematica treats the list as a vector, and does all of the multiplication and addition for us!  The first function is calculated just to show you how well we reconstruct the initial condition.  The second can be used to calculate the time evolution of the wave.

ψ0approx=coefs . ϕfxns
ψapprox=coefs . Φfxns

Plot[{ψ,ψ0approx+1},{x,0,1},PlotRange->All,PlotStyle->{RGBColor[1,0,0],RGBColor[0,0,1]}]

Plot3D[((Abs[ψapprox])^2),{x,0,1},{t,0,1},PlotPoints->60,PlotRange->All]