Animating Schrodinger Wave Function(ψ) of a Particle Using Python (with full code)

Solving Particle in a Box Using Crank-Nicolson Method

Kowshik chilamkurthy
Nerd For Tech
4 min readMar 2, 2021

--

Left picture: Source, Right: Author generated
Wave Function Animation of a Particle in a Box

Introduction

The dual nature of matter is a celebrated notion amongst physicists. Matter at atomic scale in some circumstances behaves as particles while in some, they behave like waves. To explain this we introduce the wave function ψ(x,t), which describes not the actual position of a particle, but the probability of finding the particle at a given point. The wave function ψ(x,t) or the probability field, which satisfies a perhaps the most important partial differential equation, at least for physicists, is the Schrodinger equation.

The Schrodinger Equation, Generated by author

One Dimension Schrodinger Equation

We will look at the Schrodinger equation in one dimension. The method to solve wave function in two or three dimensions are basically the same as for one dimension. But for visualisation and in the interests of time, we’ll stick with one dimension. Let’s derive the Schrodinger equation for one dimension case.

1D Schrodinger Equation, Generated by author

Solving Particle in a Box Using Crank-Nicolson Method

Box, generated by author

We will solve the wave equation for a our particle that is in a box with impenetrable walls. The idea is to solve the equation in a finite-sized space. But why in impenetrable walls? this condition forces the wave function to be zero at the walls, which we’ll put at x = 0 and x = L. We will replace the second derivative in the Schrodinger equation with a finite difference and applying Euler’s method.

Applying Euler’s method to 1D Schrodinger Equation

The above derivation enables us to solve the Schrodinger equation recursively. The boundary conditions at x = 0 and x = L for all t the wave function ψ(x,t) = 0 . In between these points we have grid points at a, 2a, 3a, and so forth. Let us arrange the values ψ(x,t) of at these interior points into a vector.

Solving Crank-Nicolson Equation using the tridiagonal method, generated by author

Now Things are straight forward, we have a propagating function :
Aψ(t+h) = Bψ(t), where the matrices A and B are both symmetric and tridiagonal. We will have to initialise the wave function at time step t= 0 , ψ(0). Using the propagation function we can approximate ψ(h) and then using ψ(h) we can approximate ψ(2h) and so on. At time t = 0 the wave- function ψ(0) of the particle has the form.

wave- function ψ(0)

This expression for ψ(0) is not normalized and there should really be an overall multiplying coefficient to make sure that the probability density for the particle integrates to unity.

Wave Function Animation of a Particle in a Box

We will try to animate the particle in a box with impenetrable walls using the Crank-Nicolson method. We will need to calculate the vector ψ(x, t) at all time steps across the grid, given the initial wave function ψ(0) and using spatial slices (N = 1000) with slice length = L/N.

Wave Function Animation of Particle in a Box, Generated by author
Generated by author

Full Code 🤩

--

--