Part IV: Using Mathematica for Visualization

(*For the ability to insert symbols like Greek letters and generally make your Mathematica notebook look "pretty," go to Palettes --> Basic Math Assistant. Check out the various tabs under "Typesetting".*)
(*Be sure to always hit Shift+Enter after entering a command.*)

(*Here's our general formula for the wavefunction, only valid from 0 to L. This is how you can define a piecewise function in Mathematica. I used "En" for the energy E, because E is a built-in symbol for exponentials.*)
ψ[x_,t_]:=Piecewise[{{0,x<0},{A Exp[-I*En*t/ℏ] Sin[((π x)/L)],0≤x≤L},{0,x>L}}]

(*Insert your formula for ρ[x]. Use the above template for defining a piecewise function.*)
ρ[x_]:=

(*Insert your normalization constant, A, here.*)
A:=

(*If we set L = 1, then all of our positions x are multiples of L. Likewise, if we define En and ℏ to be 1, then all our times are in multiples of ℏ/E*)
L:=1
En:=1
ℏ:=1

(*Plot the probability density as a function of position*)
Plot[ρ[x],{x,-L*0.5,1.5*L},AxesLabel->{"x/L","|ψ(x)((|)^2)/L"}]

Part V: Using Mathematica for Calculation

(*Let's use Mathematica's built in functions to check that our normalization as correct. You should be able to do all these calculations BY HAND on your homework, but feel free to check your answers using these functions.*)

(*To calculate an integral from 0 to L. What is the purpose of this?*)
Integrate[ρ[x],{x,0,L}]

(*Type a command to calculate the expectation value of the position*)

(*Type a command to calculate the probability that the particle will be found from 0 to L/3. To find a numerical answer, the command N[%] produces a numerial answer from the previous output.*)

Part VI: Using Mathematica to Visualize the Wave function
Don't run this part until you've completed questions 1 and 2!

(*Plot the real (solid) and imaginary(dashed) parts of the wavefunction as a function of space (x-axis) and time (animated in time).*)
Animate[Show[Plot[{Re[ψ[x,t]],Im[ψ[x,t]]},{x,0,L},PlotRange-> {-2,2},PlotStyle->{Solid,Dashed},AxesLabel->{"x/L","ψ/(Sqrt[L])"}]],{t,0,4Pi}]