Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Solving differential equations
When solving differential equations it helps to specify which variables are real and which are positive using the assume() command.
You need to specify the independent variable of your function. In this case we specify that is a function of .
The differential equation is defined using the Python def method.
This creates a function which we can differential, integrate, or solve using the differential equation solver.
Use desolve() to solve the differential equation. The arguments of desolve() are the differential equation to solve, the dependent variable ( in this case), and the independent variable x (specified using ivar=x to indicate the independent variable).
Find general solution to Schrodinger's equation
The time-independent Schrodinger's equation in one dimension is . For an infinite square well of width the potential energy function is given by
[ V(x) = \left{ \right. ]
Note: To solve this differential equation we set the potential energy to zero inside the box and rearrange Schrodinger's equation so it has the form (\frac{-\hbar^2}{2m} \frac{d^2}{dx^2}\psi(x) - E \psi(x) = 0).
Satisfying boundary conditions
The boundary conditions require that (\psi(x,t)) must be zero at the two walls. In other words, (\psi(x=0,t)=0) and (\psi(x=L,t)=0). Since (\sin(0)=0) and (\cos(0)=1), this means that (K_2=0). The boundary condition at (x=L) says that (K_1 \sin(\sqrt{2 \mathcal{E} m} x/\hbar) = 0) which is true if the argument of (\sin()) is an integer multiple of (\pi). Thus (\frac{\sqrt{2 m \mathcal{E}}L}{\hbar} = n \pi) for (n = 1, 2, 3, ...). To be consistent with previous notation we will set (A_0 = K_1). The wave function for the particle in a box is [\psi(x,t) = A_0 \sin(\frac{n \pi x}{L}).]
Integrating functions
To integrate the function f(x) you can either use f(x).integrate(x) or integrate(f(x),x).
For a definite integral, instead of just specifying the integration variable x you should specify the variable and the limits [x,0,L].
Integrals frequently gives errors asking if a quantity is positive, negative, or zero. Use assume() commands to resolve this question.
Deterimine normalization constant
The integral of the probability density over some region of space gives the probability of finding the particle in that region. If we integrate over all possible places the particle might be, the total probability has to be 1 ( which corresponds to 100%). We can use this fact to find the normalization constant (A_0). In other words, by requiring (\int_0^L \psi^*(x,t) \psi(x,t) dx = 1) we can solve for (A_0).
More integration examples
Check orthogonality of infinite square well solutions
The wave functions for differing values of should be orthogonal to one another. This means that
2D plots of functions
To plot a function (f(x)) vs. (x) from (x=0) to (x=2), use plot(f(x),[x,0,2])
You can change the color of the line plotted by setting the color argument (e.g. color='black')
Multiple graphs can be combined into a single plot window by adding the plot() commands together.
Plots have various properties, such as line color, type of line, points plotted, titles, and axes labels that can be changed
Use the show() command to display a plot
When plotting functions with unspecified variables, set all variables to 1 using .substitute().
Plot wave function and probabilty density
The following commands demonstrate how to plot the wave function and probability densities for the first three lowest energy states of the 1D particle-in-a-box.
Since the potential energy (and thus the Hamiltonian) is symmetric about the center of the well (about the point (x=L/2)), the wave functions will either be symmetric or antisymmetric about (x=L/2). Since we haven't specified the length of the box we will set (L=1) for purposes of plotting.
For you to try:
How does the number of peaks of the wave function compare to the value of n? How does the number of nodes of the wave function compare to the value of n? To help answer this question, plot the wave functions for the n=4 and n=5 states and see if they agree with your answer to these two questions. You can use psi_well(x,n) to define your wave functions.
Another example of integration
SageMath will leave answers in exact form (e.g. 1/4 or pi) so to get numerical approximations you must use .n()
You can specify how many digits are returned using .n(digits=3)
Probabilities to find the particle
The probability to find a particle between (x=a) and (x=b) is found by integrating the probability density over the region: [\int_a^b \psi^*(x) \psi(x) dx ]
What is the probability to find the particle somewhere in the box?
What is the probability of finding the particle in the left half of the box (between and )?
What is the probability of finding the particle in the left quarter of the box (between and )?
For you to try:
How do you think these three probabilities would differ for the state?
Calculate the probability for the particle to be somewhere inside the well, in the left half of the well, and in the left quarter of the well for the state. Compare these results to the answers for the state.
Expanding symbolic answers and obtaining numerical results
Calculating expectation values
.expand()
will distribute terms and expand powers in a symbolic expressionNote: When using
.expand()
on an express (rather than a variable), it helps to put parenthese around the expression.This won't work
3*(x+y).expand()
but(3*(x+y)).expand()
will work.
SageMath keeps results in exact form (e.g. rather than ) but you can force SageMath to give an approximate answer using
.n()
You can specify the number of digits the approximate result should have using
.n(digits=3)
What is the expected value of the position of the particle ?
Time-dependent behavior of the wave function and probability densities
For you to try:
Why does the wave function oscillate but the probability density does not? (Hint: the probability density involves multiplying the wave function by its complex conjugate)
Plot the wave function and probability density for the n=2 state and see if it displays the same behavior.
Animate plot of superposition of two states
For you to try:
Why does the probability density of the superposition state vary with time while the pure n=1 and n=2 states do not vary (Hint: The time dependence of the wave function is contained in the term (e^{iE_n t/\hbar}). What happens to this time dependence when you calculate (\psi^* \psi) for the pure n=1 state or n=2 state? )
Plot the real part of a superposition of the n=1 and n=3 states . Remember that the time dependency is where where we have assumed , , and for plotting purposes.
Project Ideas and Problems to Solve
Normalize a 50/50 superposition of the n=1 and n=3 state where (\psi_{super}(x,t)=A_{norm}\left( \psi_{n=1}(x,t)+\psi_{n=3}(x,t)\right)). In other words, find the value of (A_{norm}) such that (\int_{-\infty}^{\infty}\psi^*(x,0) \psi(x,0) dx = 1).
Calculate [removed] for a particle in a superposition of the n=1 and n=3 states (\psi_{super}(x,t)=\psi_{n=1}(x,t)+\psi_{n=3}(x,t)).
Use the fact that the uncertainty of an observable is defined as (\Delta A = \sqrt{< A^2 > - < A >^2}) to find the uncertainty in the position and momentum for the first three states.
Repeat the previous question for the superposition of the n=1 and n=3 states.