Numerical Techniques:
Differential Equations -
Legendre Polynomials
& Hermite Polynomials
Dr. Cem Özdo
˘
gan
LOGIK
Special Functions
Legendre Polynomials
Hermite Polynomials
Quantum Harmonic
Oscillator
9.1
Lecture 9
Numerical Techniques : Differential
Equations - Legendre Polynomial s &
Hermite Polynomi als
Quantum Harmonic Oscillator
IKC-MH.55 Scientific Computing with Python at December 22,
2023
Dr. Cem Özdo
˘
gan
Engineering Sciences Department
˙
Izmir Kâtip Çelebi University
Numerical Techniques:
Differential E quations -
Legendre Polynomials
& Hermite Polynomials
Dr. Cem Özdo
˘
gan
LOGIK
Special Functions
Legendre Polynomials
Hermite Polynomials
Quantum Harmonic
Oscillator
9.2
Contents
1 Special Functions
2 Legendre Polynomials
3 Hermite Polynomials
Quantum Harmonic Oscillator
Numerical Techniques:
Differential E quations -
Legendre Polynomials
& Hermite Polynomials
Dr. Cem Özdo
˘
gan
LOGIK
Special Functions
Legendre Polynomials
Hermite Polynomials
Quantum Harmonic
Oscillator
9.3
Partial Differential Equations; heat & temperature I
Consider a straight rod along which there is a uniform ow
of heat.
Let u(x, t) denote the temperature of the rod at time t and
location x..
Let q(x, t) de note the rate of heat flow.
The expression q/∂x denotes the rate at which the rate
of heat ow changes per unit length and therefore
measures the rate at which heat is accumulating at a given
point x at time t.
If heat is accumulating, the temperature at that point is
rising, and the rate is denoted by u/∂t.
1 The principle of conservation of energy leads to
q/x = k u/∂t, where k is the specific heat of the rod.
This means that the rate at which heat is accumulating at
a point is proportional to the rate at which the temperature
is increasing.
Numerical Techniques:
Differential E quations -
Legendre Polynomials
& Hermite Polynomials
Dr. Cem Özdo
˘
gan
LOGIK
Special Functions
Legendre Polynomials
Hermite Polynomials
Quantum Harmonic
Oscillator
9.4
Partial Differential Equations; heat & temperature II
2
A second relationship between q and u is obtained from
Newton’s law of cooling, which states that q = K (u/∂x).
Elimination of q between these equations leads to
2
u
x
2
= (k/K )
u
t
the partial differential equation for one-dimensional heat
flow.
The partial differential equation for heat flow in three
dimensions takes the form
2
u
x
2
+
2
u
y
2
+
2
u
yx
2
= (k/K )
u
t
Often w ritten as
2
u = (k/K )
u
t
where the symbol , called del or nabla, is known as the
Laplace operator.
Numerical Techniques:
Differential E quations -
Legendre Polynomials
& Hermite Polynomials
Dr. Cem Özdo
˘
gan
LOGIK
Special Functions
Legendre Polynomials
Hermite Polynomials
Quantum Harmonic
Oscillator
9.5
Partial Differential Equations III
Another example to PDEs for dealing with wave
propagation problem:
2
u = (1/c
2
)
2
u
t
2
where c is the speed at which the wave pr opagates.
PDEs ar e harder to solve than ordinary differential
equations (ODEs).
However, the PDEs associated with wave propagation and
heat flow can be reduced to a system of ODEs through a
process known as separation of variables.
These ODEs depend on the choice of coordinate system,
which in turn is influenced by the physical configuration of
the problem.
The solutions of these ODEs form the majority of the
special functions of mathematical physics.
Numerical Techniques:
Differential E quations -
Legendre Polynomials
& Hermite Polynomials
Dr. Cem Özdo
˘
gan
LOGIK
Special Functions
Legendre Polynomials
Hermite Polynomials
Quantum Harmonic
Oscillator
9.6
Special Functions
In the br oad sense, a set of several classes of functions
that arise in the solution of both theoretical and applied
problems in various branches.
In the narrow sense, the special functions of mathematical
physics, which aris e when solving PDEs by the method of
separation of variables.
Special functions can be defined by means of power
series, generating functions, infinite products, repeated
differentiation, integral representations, differential,
difference, integral, and functional equations, trigonometric
series, or other series in orthogonal functions.
For example, in solving the equations of heat flow or wave
propagation in cylindrical coordinates, the method of
separation of variables leads to Bessel’s differential
equation, a solution of which is the Bessel function,
denoted by J
n
(x).
Numerical Techniques:
Differential E quations -
Legendre Polynomials
& Hermite Polynomials
Dr. Cem Özdo
˘
gan
LOGIK
Special Functions
Legendre Polynomials
Hermite Polynomials
Quantum Harmonic
Oscillator
9.7
Polynomials
A polynomial ("many terms") is defined as an expression
that consist of variables, coefficients and exponents.
A polynomial can have:
variables (like x and y)
constants/coefficie nts (like 6, -10, or
3/2
)
exponents (like the 2 in y
2
)
that can be combined using addition, subtraction,
multiplication and divisio n
but not division by a variable (so something like 2/x is not
correct)
a monomia l is the product of non-negative powers of
variables and will only have one term. 13, 3x, 4y
2
, ...
a bino mial is the sum of two monomials. 3x + 1, 2x + y, ...
a tri nomial is the sum of three mo nomials. x
2
+ 2x + 1, 2x
+ 3y + 2, ...
can have one or more terms, but not an infinite number of
terms.
The standard form of a polynomial refers to writing a
polynomial in the descending power of the variable.
2x
3
4x
2
+ 7x 4
Numerical Techniques:
Differential E quations -
Legendre Polynomials
& Hermite Polynomials
Dr. Cem Özdo
˘
gan
LOGIK
Special Functions
Legendre Polynomials
Hermite Polynomials
Quantum Harmonic
Oscillator
9.8
Legendre’s Equation
The Legendre polynomials P
(x), sometimes called
Legendre functions of the first kind, Legendre coeffic ients,
or zonal harmonics are solutions to the Legendre
differential equation.
The Legendre polynomials satisfy the second-order
differential equation.
(1 x
2
)
d
2
y
dx
2
2x
dy
dx
+ ( + 1)y = 0
where y = P
(x)
This equation has two regular singular points x = ±1
where the leading coefficient (1 x
2
) vanishes.
Solutions of Legendre equations are Legendre
polynomials
P
(x) =
1
2
!
d
dx
(x
2
1)
Numerical Techniques:
Differential E quations -
Legendre Polynomials
& Hermite Polynomials
Dr. Cem Özdo
˘
gan
LOGIK
Special Functions
Legendre Polynomials
Hermite Polynomials
Quantum Harmonic
Oscillator
9.9
Legendre Polynomials I
If (0 ) is an integer, they ar e polynomials and
make up an infinite set of functions of the variable x.
We therefore have a function P
0
(x), another function
P
(x), and an infinite number of additional functions
belonging to the set of Legendre polynomials.
Introduce a (generating) function Φ(x, h) of two variables,
known as a generating function for the definition of the
Legendre polynomials.
Φ(x, h) = (1 2xh + h
2
)
1/2
The first variable, x, is the same variable that appear s as
the argument of the Legendre polynomials.
The second variable, h, is an auxiliary variable with no
particular meaning.
Numerical Techniques:
Differential E quations -
Legendre Polynomials
& Hermite Polynomials
Dr. Cem Özdo
˘
gan
LOGIK
Special Functions
Legendre Polynomials
Hermite Polynomials
Quantum Harmonic
Oscillator
9.10
Legendre Polynomials II
Think of Φ as a function of a single variable h (Φ = Φ(h))
and expand as a Taylor expansion in powers of h
Φ(h) = Φ(0) +
dΦ
dh
h=0
h +
1
2!
d
2
Φ
dh
2
h=0
h
2
+
1
3!
d
3
Φ
dh
3
h=0
h
3
+ . . .
=
X
=0
1
!
d
Φ
dh
h=0
h
Restore the x-dependence of the generating function. This
doesn’t change the general appearance of the Taylor
expansion but written as partial derivatives instead of total
derivatives.
Φ(x, h) =
X
=0
1
!
Φ
h
h=0
h
=
X
=0
P
(x)h
Right hand side of this equation is the formal definition of
the Legendre polynomials. They are identified as the
coefficients in the Taylor expansion of the generating
function about h = 0.
Numerical Techniques:
Differential E quations -
Legendre Polynomials
& Hermite Polynomials
Dr. Cem Özdo
˘
gan
LOGIK
Special Functions
Legendre Polynomials
Hermite Polynomials
Quantum Harmonic
Oscillator
9.11
Legendre Polynomials III
Let us use this equation to calculate the first few
polynomials.
For = 0 we are instructed to take no derivatives, and to
evaluate the generating function at h = 0. This gives
P
0
(x) = 1; the zeroth po lynomial is actual ly a constant.
Moving on to = 1, we must differenti ate Φ once with
respect to h. Evaluating th is at h = 0 a nd divi ding by 1! = 1
gives P
1
(x) = x.
For = 2 we differentiate Φ twice. Evaluatin g this at h = 0
and dividing by 2! = 2 prod uces P
2
(x) = 1/2(3x
2
1). We
can just keep going like this, an d generate any number of
polynomials.
When is even, P
(x) contains only even powers of x,
starting with x
and ending with x
0
.
When is odd, P
(x) contains only odd powers of x,
starting with x
and ending with x.
P
(x) is an even function of x when is even, and an odd
function of x when is odd.
Numerical Techniques:
Differential E quations -
Legendre Polynomials
& Hermite Polynomials
Dr. Cem Özdo
˘
gan
LOGIK
Special Functions
Legendre Polynomials
Hermite Polynomials
Quantum Harmonic
Oscillator
9.12
Legendre Polynomials IV
The rst few Legendre polynomials are given by
P
0
= 1
P
1
= x
P
2
=
1
2
(3x
2
1)
P
3
=
1
2
(5x
3
3x)
P
4
=
1
8
(35x
4
30x
2
+ 3)
P
5
=
1
8
(63x
5
70x
3
+ 15x)
P
6
=
1
16
(231x
6
315x
4
+ 105x
2
5)
Recursion relation:
P
(x) =
1
[(2 1)xP
1
(x) ( 1)P
2
(x)]
Numerical Techniques:
Differential E quations -
Legendre Polynomials
& Hermite Polynomials
Dr. Cem Özdo
˘
gan
LOGIK
Special Functions
Legendre Polynomials
Hermite Polynomials
Quantum Harmonic
Oscillator
9.13
Legendre Polynomials V
Example py-file: The program to find first 6 Legendre
polynomials:
myLegendre.py
Figure: First 6 Legendre Polynomials P
(x) with Recursion Relation:
P
(x) =
1
[(2 1)xP
1
(x) ( 1)P
2
(x)].
Numerical Techniques:
Differential E quations -
Legendre Polynomials
& Hermite Polynomials
Dr. Cem Özdo
˘
gan
LOGIK
Special Functions
Legendre Polynomials
Hermite Polynomials
Quantum Harmonic
Oscillator
9.14
Legendre Polynomials VI
−1.00 −0.75 0.50 −0.25 0.00 0.25 0.50 0.75 1.00
x
−1.00
−0.75
−0.50
−0.25
0.00
0.25
0.50
0.75
1.00
P
(
)
First
6 Legendre Polynomials
P
(
)
P
(
) =
1
[(2
1)
P
1
(
) (
1)
P
2
(
)]
l=1
SciPy l=1
l=2
SciPy l=2
l=3
SciPy l=3
l=4
SciPy l=4
l=5
SciPy l=5
l=6
SciPy l=6
Figure: Plot of first 6 P
(x).
Numerical Techniques:
Differential E quations -
Legendre Polynomials
& Hermite Polynomials
Dr. Cem Özdo
˘
gan
LOGIK
Special Functions
Legendre Polynomials
Hermite Polynomials
Quantum Harmonic
Oscillator
9.15
Hermite’s Equation
The H ermite polynomials H
k
(x) are solutions to the
Hermite differential equation of the form
a(x)y
′′
+ b(x)y
+ c(x)y = 0
where a(x ) = 1, b(x ) = 2x and c(x) = 2k (positive
integer parameter k)
d
2
y
dx
2
2x
dy
dx
+ 2ky = 0
y
k
is a solution of the Hermite equation. Therefore,
defining H
k
(x) = y
k
.
A natural one to define Hermite polynomials is through the
so-called Rodrigues’formula:
H
k
(x) = (1)
k
e
x
2
d
k
dx
k
h
e
x
2
i
Numerical Techniques:
Differential E quations -
Legendre Polynomials
& Hermite Polynomials
Dr. Cem Özdo
˘
gan
LOGIK
Special Functions
Legendre Polynomials
Hermite Polynomials
Quantum Harmonic
Oscillator
9.16
Hermite Polynomials I
The rst few Hermite polynomials are given by
H
0
= 1
H
1
= 2x
H
2
= 4x
2
2
H
3
= 8x
3
12x
H
4
= 16x
4
48x
2
+ 12
H
5
= 32x
5
160x
3
+ 120x
H
6
= 64x
6
480x
4
+ 720x
2
120
Recursion relation:
H
k+1
(x) = 2xH
k
(x) 2kH
k1
(x)
Numerical Techniques:
Differential E quations -
Legendre Polynomials
& Hermite Polynomials
Dr. Cem Özdo
˘
gan
LOGIK
Special Functions
Legendre Polynomials
Hermite Polynomials
Quantum Harmonic
Oscillator
9.17
Hermite Polynomials II
Example py-file: The program to find first 6 H ermite
polynomials:
myHermite.py
Figure: First 6 H ermite Polynomials H
k
(x) with Recursion Relation:
H
k+1
(x) = 2xH
k
(x) 2kH
k1
(x).
Numerical Techniques:
Differential E quations -
Legendre Polynomials
& Hermite Polynomials
Dr. Cem Özdo
˘
gan
LOGIK
Special Functions
Legendre Polynomials
Hermite Polynomials
Quantum Harmonic
Oscillator
9.18
Hermite Polynomials III
4 −3 2 −1 0 1 2 3 4
x
40
20
0
20
40
H
k
(
x
)
First 6 Hermite Polynomials
H
k
(
x
)
H
k
+ 1
(
x
) = 2
xH
k
(
x
) 2
kH
k
1
(
x
)
k=1
SciPy k=1
k=2
SciPy k=2
k=3
SciPy k=3
k=4
SciPy k=4
k=5
SciPy k=5
k=6
SciPy k=6
Figure: Plot of first 6 H
k
(x).
Numerical Techniques:
Differential E quations -
Legendre Polynomials
& Hermite Polynomials
Dr. Cem Özdo
˘
gan
LOGIK
Special Functions
Legendre Polynomials
Hermite Polynomials
Quantum Harmonic
Oscillator
9.19
Quantum Harmonic Oscillator I
The quantum harmonic oscillator as analog of the
classical one is often used as an approximate model for
the behavior of some quantum systems.
It is one of the few quantum-mechanical systems for which
an exact, analytical solution is known.
The H amiltonian for a particle of mass m moving in one
dimension in a potential V (x ) = 1/2kx
2
is
ˆ
H =
ˆ
p
2
2m
+
1
2
k
ˆ
x
2
=
ˆ
p
2
2m
+
1
2
mω
2
ˆ
x
2
where
ˆ
x is the position operator, and
ˆ
p is the momentum
operator (given by
ˆ
p = i~/∂x in the coordinate basis).
The rst term in the Hamiltonian represents the kinetic
energy of the particle, and the second term represents its
potential energy, as in Hooke’s law.
Numerical Techniques:
Differential E quations -
Legendre Polynomials
& Hermite Polynomials
Dr. Cem Özdo
˘
gan
LOGIK
Special Functions
Legendre Polynomials
Hermite Polynomials
Quantum Harmonic
Oscillator
9.20
Quantum Harmonic Oscillator II
Then, Schrödinger equation becomes
~
2
2m
d
2
ψ
dx
2
+
1
2
kx
2
ψ = Eψ
with the change of variable, q = (mk/~
2
)
1/4
x, this
equation becomes
1
2
d
2
ψ
dq
2
+
1
2
q
2
ψ =
E
~ω
ψ
where ω =
p
k/m is the angular frequency of the
oscillator.
This differential equation has an exact solution in terms of
a quantum number ν = 0, 1, 2, . . .:
ψ(q) = N
ν
H
ν
(q)e
q
2
/2
where N
ν
= (
π2
ν
ν!)
1/2
is a normalization constant.
The func tion H
ν
(q) is the physicists’ Hermite polynomials
of order ν, defined by:
H
ν
(q) = ( 1)
ν
e
q
2
d
ν
dq
ν
e
q
2
Numerical Techniques:
Differential E quations -
Legendre Polynomials
& Hermite Polynomials
Dr. Cem Özdo
˘
gan
LOGIK
Special Functions
Legendre Polynomials
Hermite Polynomials
Quantum Harmonic
Oscillator
9.21
Quantum Harmonic Oscillator III
The corresponding energy levels are
E
ν
= ~ω
ν +
1
2
= (2ν + 1)
~
2
ω
Recursion formula:
H
ν+1
(q) = 2qH
ν
(q) 2νH
ν1
(q)
with the first two: H
0
= 1 and H
1
= 2q.
Example py-file: The program to find the harmonic oscillator
wavefunctions/probability densities for up to 4 vibrational
energy levels with the harmonic potential, V = q
2
/2.
QHO.py
Numerical Techniques:
Differential E quations -
Legendre Polynomials
& Hermite Polynomials
Dr. Cem Özdo
˘
gan
LOGIK
Special Functions
Legendre Polynomials
Hermite Polynomials
Quantum Harmonic
Oscillator
9.22
Quantum Harmonic Oscillator IV
4 2
0 2 4
q
1
2
¯
v = 0
3
2
¯
v = 1
5
2
¯
v = 2
7
2
¯
v = 3
9
2
¯
v = 4
ψ(q)
Figure: Wavefunction representations for the first 5 boun d
eigenstates, ν = 0 4.
Numerical Techniques:
Differential E quations -
Legendre Polynomials
& Hermite Polynomials
Dr. Cem Özdo
˘
gan
LOGIK
Special Functions
Legendre Polynomials
Hermite Polynomials
Quantum Harmonic
Oscillator
9.23
Quantum Harmonic Oscillator V
4 2
0 2 4
q
1
2
¯
v = 0
3
2
¯
v = 1
5
2
¯
v = 2
7
2
¯
v = 3
9
2
¯
v = 4
|ψ(q)|
2
Figure: Correspon ding probability densities.