(*Example Notebook: Wavefunctions, Normalization*)
(*See the MmaTutorial.nb for a more detailed tutorial*)
(*You may find it helpful to tell Mathematica that some of your variables are reals, or integers, or > 0*)
$Assumptions=n>0 &&n∈Integers&&L∈Reals&&L>0 && ω∈Reals && ω>0

Using Mathematica to help find the normalization constant, expectation value, and standard deviation.

(*What is A? Use the normalization condition. The result of this integral must equal 1.*)
Integrate[ (((A*Sin[π x/L]))^2),{x,0,L}]

(*Knowing that the result must be equal to 1, solve for A (by hand) and tell Mathematica the value for future use. We could have messed with some more complicated routine to ask Mathematica to "solve" for A, but sometimes relying on the computer makes things more complicated than using your noggin.*)
A:=(Sqrt[(2/L)])

(*NOTE that if you now run the same calculation, because A is now defined you will get a result of 1!*)
Integrate[ (((A*Sin[π x/L]))^2),{x,0,L}]

(*Expectation value for position? Can calculate exactly. You should be able to do this by hand using integration by parts (or reason it out), but let's check our answer.*)
Integrate[x (A^2)((Sin[π x/L])^2),{x,0,L}]

(*Standard deviation? Recall that σ=(Sqrt[<x^2> - <x>^2]). We already have <x> from the previous question, so let's find the expectation value of x^2. *)
Integrate[(x^2) (A^2)((Sin[π x/L])^2),{x,0,L}]

(*It's nice to have an exact expression, but let's get the numerical approximation as well. The percent sign means "use the previous output as input for this cell." Note if you run your cells out of order, results may be unexpected...*)
N[%]

Using Mathematica to visualize the result.

(*Let's input our mean and standard deviation for use in our plots*)
μ:=L/2
σ:=(Sqrt[((π^2)-6)(L^2)/(12(π^2))])

(*We can't have variables when we plot a function, but we can express everything in terms of L = 1 to get an idea of the shape. So for example, if L = 2.0 m, then the x-axis scale would be from 0 to 2.0 m. In the graph below, I have labeled my axes, and also plotted vertical lines to indicate the locations of the mean and the mean +/- sigma*)
L:=1
Plot[(Sqrt[(2/L)])Sin[π x/L],{x,0,L},AxesLabel->{"x/L","Ψ(x,t)"},GridLines->{{μ-σ,μ,μ+σ},{}}]

(*How about the probability density function?*)
Plot[(2/L)((Sin[π x/L])^2),{x,0,L},AxesLabel->{"x/L","|Ψ(x,t)((|)^2)"},GridLines->{{μ-σ,μ,μ+σ},{}}]

(*Just a comparison for fun... how does this compare to a Gaussian probability density function of the same width? They're not quite the same shape.*)
g[x_]:=(1/(σ(Sqrt[2π])))Exp[-(((((x-μ))^2) )/(2(σ^2) ))]
Plot[g[x],{x,0,L},GridLines->{{μ-σ,μ,μ+σ},{}}]