Solutions to Differential Equations: Special Functions

Visualizing a few special functions

Bessel's equation

Bessel's equation is a second-order ODE having the following form, with the parameter ν being real and nonnegative.

BesselODE = (x^2) y''[x]  +  
          x y'[x]  + ((x^2) - (ν^2)) y[x]  == 0

Bessel's equation arises in problems in heat conduction and mass diffusion for problems with cylindrical symmetry (and many other situations). It's solution is a linear combination of two special functions called Bessel functions of the first kind, BesselJ in Mathematica, and Bessel functions of the second kind, BesselY in Mathematica.

DSolve[BesselODE,  y[x], x]

The functions BesselJ and BesselY can be evaluated numerically and of course Mathematica has this capability built-in.

MyPlotStyle[HowMany_Integer]  :=  
      Table[{Hue[0.66*i/HowMany], Thickness[0.01]}, {i, 0, 
          HowMany}]

Plot[{BesselJ[0, x],  BesselY[0, x]}, {x, 0, 20},  
      PlotStyle -> MyPlotStyle[2]]

Plot[{BesselJ[5, x],  BesselY[5, x]}, {x, 0, 20},  
      PlotStyle -> MyPlotStyle[2]]

Plot[{BesselJ[1/2, x],  BesselY[1/2, x]}, {x, 0, 20},  
      PlotStyle -> MyPlotStyle[2]]

As an example of an application where the Bessel functions arise, consider radially-symmetric heat flow in an infinitely long cylinder of radius a that has an initial temperature profile T =T(r) and a surface temperature T(r = a) = (Subscript[T, r]), 
      and  substitute T =  (e^(-κ(α^2) 
                t)) τ into the heat equation ∂(T/∂)t = κ (∇^2) 
            T in cylindrical coordinates. The function τ must obey\(TraditionalForm\`\(\(\(\(d\^2\) τ\)\/∂r\^2 + \ \(1\/r\) dτ\/dr + \ \(α\^2\) τ = \ 0\)\(,\)\)\) which has the form of Bessel's equation of order ν = zero. The solution will have the form T= A (Subscript[J, 0])(αr)(e^(-κ(α^2) t)) where A is a constant and (Subscript[J, 0])(αr)is the Bessel function of order zero of the first kind. The parameter α must, from boundary conditions, be a solution to the equation J(αa) = 0. The initial temperature distribution, f(r), can be expanded as a series of Bessel functions of zero order, analogous to what we did with Fourier series. The general solution to the heat-flow problem will then be an infinite series of Bessel functions, each modified by an exponentially decaying amplitude, taking the form T= (∑_(n = 1)^∞)(Subscript[A, n]) (Subscript[J, 0])((Subscript[α, n]) r)(e^(-κ((Subscript[α, n])^2) 
                    t)).  For a more thorough discussion, see H.S. Carslaw and J.C. Jaeger, Conduction of Heat in Solids, Oxford University Press, Second Edition, pp. 194–196 (1959).

Legendre's equation

Legendre's equation is a second-order ODE having the following form, with the parameters m and n being integers such that n is positive and -n ≤ m ≤ n (seems to suggest applications to quantum numbers!). Legendre's equation arises in physical problems with spherical symmetry. The simplest form of the equation has only one parameter, n and takes the form:

LegendreODE = (1 - (x^2)) y''[x]  - 
          2 x y'[x]  + (n (n + 1)) y[x]  == 
        0

Its solution is a linear combination of two special functions, Legendre and PLegendreQ:

DSolve[LegendreODE,  y[x], x]

The two-parameter form of the Legendre equation is:

AnotherFormLegendreODE = (1 - (x^2)) y''[x]  - 
          2 x y'[x]  + (n (n + 1) - ((m^2)/(1 - (x^2)))) 
            y[x]  == 0

which has a solution involving the same special functions:

DSolve[AnotherFormLegendreODE,  y[x], x]

Of course, Mathematica can evaluate and plot Legendre functions…

Plot[{LegendreP[0, x],  LegendreQ[0, x]}, {x, -1, 1},  
      PlotStyle -> MyPlotStyle[2]]

Plot[{LegendreP[1, x],  LegendreQ[1, x]}, {x, -1, 1},  
      PlotStyle -> MyPlotStyle[2]]

Plot[{LegendreP[2, x],  LegendreQ[2, x]}, {x, -1, 1},  
      PlotStyle -> MyPlotStyle[2]]

Plot[Evaluate[Table[LegendreP[i, x], {i, 0, 10}]], {x, -1, 1},  
      PlotStyle -> MyPlotStyle[11]]

Plot[Evaluate[Table[LegendreQ[i, x], {i, 0, 10}]], {x, -1, 1},  
      PlotStyle -> MyPlotStyle[11]]

Note how some of the Legendre functions are even and some are odd.  Recall that by summing even and odd functions, functions that are neither even or odd can be produced.

Hypergeometric and Laguerre special functions

Here is another differential equation whose solution involves special functions.  Many special functions are defined and analyzed precisely because they are solutions to simple ODEs

DSolve[
      x y''[x]  +  (q   +  1  -  x) y'[x]  +  
          p  y[x]  == 0,  y[x], x]

Plot[LaguerreL[4, 1, x], {x, -5, 15}]

Using Special Functions to visualize the eigensolutions for an electron bound to a fixed proton--The Hydrogen Atom

Eigenfunctions for Hydrogen:

Preliminary Definitions:
n will be the first quantum number n =1,2,3
L will be the second quantum number L=0,1,2,... (n-1)
m will be the third quantum number m = -L,-L+1,... 0,1,2, +L
These rules come from restrictions on the special functions that make up the eigenfunctions for the H-atom

Z = 1;  a0  =  1;
κ[
        n_]  :=  κ[
          n]  =   (( Z)/(a0  n))
ρ[n_,  r_]  :=  2 κ[n] r

    
A[n_ ,  
        L_]  := A[n ,  
          L] =  (Sqrt[Factorial[n - L  -  1]/(2 n (((Factorial[n  +  L]))^3))])

    
Prefact[n_, 
        L_]  :=  Prefact[n, 
          L]  =   (((2 κ[n]))^((3/(2 )))) A[n, 
            L]
R[n_ ,  L_,  r_]  :=  
      Prefact[n, L] ρ[n, r] Exp[((-ρ[n, r])/2)] LaguerreL[
          n - L - 1, 2 L  +  1, ρ[n, r]]

The eigenfunctions for the Hydrogen Atom can now be written down.  The eigenfunctions will relate to the above definitions and involve the Spherical Harmonics which are related to Legendre functions and its derivatives.

HAtom[n_ ,  L_ ,  m_ , {r_ ,  θ_,  ϕ_}]  :=  
      R[n, L, r] SphericalHarmonicY[L, m, θ, ϕ]

<< Calculus`VectorAnalysis`

CoordinatesFromCartesian[{x, y, z}, Spherical]

SphericalCoords[x_,  y_,  z_]  :=  
      Module[{rsq =  x^2  +  y^2  +  z^2, r, phi = ArcTan[x, y]}, 
        r = Sqrt[rsq]; Return[{r, ArcCos[z/r], phi}]]

2,1,1 corresponds to a 2p spin up electron

HAtom[2, 1, 1, SphericalCoords[1, 2, 1]]

N[HAtom[2, 1, 1, SphericalCoords[1, 2, 1]]]

<< Graphics`ContourPlot3D`

Abs[
      HAtom[2, 1, 1, 
        CoordinatesFromCartesian[{0, 1,  .5}, Spherical]]]

Plot a surface of constant probability density. Only an octant can be plotted, the numerical methods do not behave well on the coordinate "zero value" planes.

p1 = 
      ContourPlot3D[
        Abs[HAtom[2, 1, 1, SphericalCoords[x, y, z]]], {x, -5, 5}, {y, 
          0.001, 5}, {z, 0.002, 5}, MaxRecursion  -> 2, 
        Contours  ->  {0.006,  0.007,  0.008}]

epsilon  =  10^(-6)

pdens = 
      NMaximize[
        Abs[HAtom[3, 2, 1, SphericalCoords[x, y, z]]], {x, y, z}]

p1 = 
      ContourPlot3D[
        Abs[HAtom[3, 2, 1, SphericalCoords[x, y, z]]], {x, -10, 10}, {y, 
          epsilon, 10}, {z, epsilon, 10}, MaxRecursion -> 2, 
        PlotPoints -> {7, 7}, Contours -> {0.95  pdens[[1]]}]

p2 = 
      ContourPlot3D[
        Abs[HAtom[3, 2, 1, SphericalCoords[x, y, z]]], {x, -10, 10}, {y, 
          epsilon, 10}, {z, -epsilon, -10}, MaxRecursion -> 2, 
        PlotPoints -> {7, 7}, Contours -> {0.95  pdens[[1]]}]

However, we can always put the octants back together like a puzzle

Show[p1, p2]

Write a function to place all the octants on one graph

HAtomShow[n_ ,  L_,  m_,  pfrac_]  :=  
      Module[{nu, nd, su, sd, pmax, plevel, whole, 
          half}, 
pmax =  
          NMaximize[
            Abs[HAtom[n, L, m, SphericalCoords[x, y, z]]], {x, y, 
              z}]; 
plevel   =  
          pfrac (pmax[[1]]); 
nu  =  
          ContourPlot3D[
            Abs[HAtom[n, L, m, SphericalCoords[x, y, z]]], {x, -10, 
              10}, {y, epsilon, 10}, {z, epsilon, 10}, 
            MaxRecursion -> 2, PlotPoints -> {5, 5}, 
            Contours -> {plevel}, 
            DisplayFunction -> Identity]; 
nd  =  
          ContourPlot3D[
            Abs[HAtom[3, 2, 1, SphericalCoords[x, y, z]]], {x, -10, 
              10}, {y, epsilon, 10}, {z, -epsilon, -10}, 
            MaxRecursion -> 2, PlotPoints -> {5, 5}, 
            Contours -> {plevel}, 
            DisplayFunction -> Identity]; 
su  =  
          ContourPlot3D[
            Abs[HAtom[n, L, m, SphericalCoords[x, y, z]]], {x, -10, 
              10}, {y, -epsilon, -10}, {z, epsilon, 10}, 
            MaxRecursion -> 2, PlotPoints -> {5, 5}, 
            Contours -> {plevel}, 
            DisplayFunction -> Identity]; 
sd  =  
          ContourPlot3D[
            Abs[HAtom[3, 2, 1, SphericalCoords[x, y, z]]], {x, -10, 
              10}, {y, -epsilon, -10}, {z, -epsilon, -10}, 
            MaxRecursion -> 2, PlotPoints -> {5, 5}, 
            Contours -> {plevel}, 
            DisplayFunction -> Identity]; 
whole  =  
          Show[nu, nd, su, sd, 
            DisplayFunction -> 
              Identity]; 
half  =   Show[nu, nd, 
            DisplayFunction -> Identity]; 
Show[
          GraphicsArray[{whole, half}], 
          DisplayFunction -> $DisplayFunction]]

It takes about a minute to compute and display one probability density contour

H210  =  HAtomShow[2, 1, 0, 0.8]

The next one takes a couple minutes, presumably because of the small probability values?

3,2,1 corresponds to a 3d spin-up electron

H321 =  HAtomShow[3, 2, 1, 0.8]

I am not sure why I am only getting the top half here...

H31m1 =  HAtomShow[3, 1, -1, 0.8]

H531 =  HAtomShow[5, 3, 1, 0.9]