Finite Difference Method - MatrixMethod
Finite Difference Method - MatrixMethod
Another way to solve the ODE boundary value problems is the finite difference method, where
we can use finite difference formulas at evenly spaced grid points to approximate the differential
equations. This way, we can transform a differential equation into a system of algebraic
equations to solve.
In the finite difference method, the derivatives in the differential equation are approximated
using the finite difference formulas. We can divide the interval of [a,b] into n equal subintervals
of length h as shown in the following figure.
Commonly, we usually use the central difference formulas in the finite difference methods due to
the fact that they yield better accuracy. The differential equation is enforced only at the grid
points, and the first and second derivatives are:
𝑑𝑦 𝑦𝑖+1 − 𝑦𝑖−1
=
𝑑𝑥 2ℎ
𝑑2 𝑦 𝑦𝑖−1 − 2𝑦𝑖 + 𝑦𝑖+1
=
𝑑𝑥 2 ℎ2
These finite difference expressions are used to replace the derivatives of y in the differential
equation which leads to a system of n+1 linear algebraic equations if the differential equation is
linear. If the differential equation is nonlinear, the algebraic equations will also be nonlinear.
……………………………
𝜓𝑛−1 −2𝜓𝑛 +𝜓𝑛+1 2𝑚
Put i=n, =− 𝐸𝜓1
ℎ2 ℏ2
In matrix form:
Let’s define the grid points xi such that:
𝑥1 = 0, 𝑥2 = ℎ, ……, 𝑥𝑛 = (𝑛 − 1)ℎ with boundary conditions 𝜓(0)= 𝜓(𝐿)=0
We will construct a matrix A such that:
2𝑚𝐸
𝐴𝜓 = 𝜓
ℏ2
This matrix A represents the finite difference approximation of the second derivative. This will
be a tridiagonal matrix, that means except the diagonal, top and bottom diagonal elements are
zero. The diagonal elements represent −2⁄ℎ2 , and the off-diagonal elements represent 1⁄ℎ2 .
The matrix looks like this for N grid points:
Therefore,
= E
Here we are basically discretizing the x using linspace. If we put just ‘N’ in linspace then the
division is little bit problem as shown in above. So it’s better to take ‘N+1’ in linspace as
following:
Next, to make the elements for upper diagonal ‘np.diag(np.ones(N-2),1)’ and lower diagonal
‘np.diag(np.ones(N-2),-1)’
To check the dimension of the matrix:
ℏ2 𝐸
Now, we will multiply the constant with matrix A and form a new matrix H:
2𝑚ℎ2
To solve the s-wave Schrödinger equation for the ground and first excited states of the
hydrogen atom using the matrix method, we first need to discretize the problem and then solve it
numerically using matrix diagonalization.
Schrödinger Equation for Hydrogen Atom (s-wave):
The radial Schrödinger equation for the hydrogen atom (with l=0l = 0l=0, i.e., s-wave) is given
by:
ℏ2 𝑑 2 𝑒 2
[− − ] 𝑢(𝑟) = 𝐸𝑢(𝑟)2
2𝑚 𝑑𝑟 2 𝑟