# Wolfram Language™

## Observe a Quantum Particle in a Box

A quantum particle free to move within a two-dimensional rectangle with sides and is described by the two-dimensional time-dependent Schrödinger equation, together with boundary conditions that force the wavefunction to zero at the boundary.

In:= ```eqn = I D[\[Psi][x, y, t], t] == -\[HBar]^2/(2 m) Laplacian[\[Psi][x, y, t], {x, y}];```
In:= ```bcs = {\[Psi][0, y, t] == 0, \[Psi][xMax, y, t] == 0, \[Psi][x, yMax, t] == 0, \[Psi][x, 0, t] == 0};```

This equation has a general solution that is a formal infinite sum of so-called eigenstates.

In:= `DSolveValue[{eqn, bcs}, \[Psi][x, y, t], {x, y, t}]`
Out= Define an initial condition equal to a unitized eigenstate.

In:= ```initEigen = \[Psi][x, y, 0] == 2 /Sqrt[xMax yMax] Sin[(\[Pi] x)/xMax] Sin[(\[Pi] y)/yMax];```

In this case, the solution is simply a time-dependent multiple (of unit modulus) of the initial condition.

In:= `DSolveValue[{eqn, bcs, initEigen}, \[Psi][x, y, t], {x, y, t}]`
Out= Define an initial condition that is a sum of eigenstates. Because the initial conditions are not an eigenstate, the probability density for the location of the particle will be time dependent.

In:= ```initSum = \[Psi][x, y, 0] == Sqrt/Sqrt[ xMax yMax] (Sin[(2 \[Pi] x)/xMax] Sin[(\[Pi] y)/yMax] + Sin[(\[Pi] x)/xMax] Sin[(3 \[Pi] y)/yMax]);```

Solve with the new initial condition.

In:= `sol = DSolveValue[{eqn, bcs, initSum}, \[Psi][x, y, t], {x, y, t}]`
Out= Compute the probability density, inserting values of the reduced Planck's constant, electron mass, and a box of atomic size, using units of the electron mass, nanometers, and femtoseconds.

In:= ```\[HBar] = QuantityMagnitude[Quantity[1., "ReducedPlanckConstant"], "ElectronMass" * ("Nanometers")^2/"Femtoseconds"]```
Out= In:= ```\[Rho][x_, y_, t_] = FullSimplify[ComplexExpand[Conjugate[sol] sol]] /. {m -> 1, xMax -> 1, yMax -> 1}```
Out= Visualize the probability density inside the box over time.

In:= ```ListAnimate[ Table[Plot3D[\[Rho][x , y , t], {x, 0, 1}, {y, 0, 1}, PlotTheme -> {"Scientific", "SolidGrid"}, AxesLabel -> {"\!\(\* StyleBox[\"x\", \"SO\"]\) (nm)", " \!\(\* StyleBox[\"y\", \"SO\"]\) (nm)", "\!\(\* StyleBox[\"\[Rho]\", \"SO\"]\) (\!\(\*SuperscriptBox[\(nm\), \ \(-2\)]\))"}, ImageSize -> Medium, PlotRange -> {0, 7}], {t, 0, 19, .5}]]``` 