Functions
Clausen functions
The Clausen function is given by
\[Cl_2(\phi)=-\int_0^\phi \log|2\sin(x/2)| \, \text{d}x\]
using Plots, FewSpecialFunctions, LaTeXStrings
plot_font = "Computer Modern"
default(
fontfamily=plot_font,
linewidth=2.5,
framestyle=:box,
label=nothing,
grid=true,
palette=:tab10,
)
x = range(0,15,1000)
xlabel!(L"ϕ")
title!("Clausen function")
plot(x,Clausen.(x), label=L"Cl_2(ϕ)")
FewSpecialFunctions.Clausen
— FunctionClausen(x, min_tol=1e-15)
Computes the Clausen function
$Cl_2(\phi) = - \int_0^\phi \log|2\sin(x/2)| dx$
Returns $Cl_2(\phi)$.
Debye functions
The Debye functions are given by
\[ D_n(x)= \frac{n}{x^n} \int_0^x \frac{t^n}{\text{e}^t-1} \, \text{d}x\]
And
using Plots, FewSpecialFunctions, LaTeXStrings
plot_font = "Computer Modern"
default(
fontfamily=plot_font,
linewidth=2.5,
framestyle=:box,
label=nothing,
grid=true,
palette=:tab10,
)
x = range(0,25,1000)
plot(x,Debye_function.(1,x),label=L"D_1(x)")
plot!(x,Debye_function.(2,x),label=L"D_2(x)")
plot!(x,Debye_function.(3,x), label=L"D_3(x)")
title!("Debye Functions")
xlabel!(L"x")
FewSpecialFunctions.Debye_function
— FunctionDebye_function(n,x,min_tol=1e-15)
The Debye function(n,x) given by
$D_n(x) = \frac{n}{x^n} \int_0^x \frac{t^n}{e^{t}-1} dx$
Returns the value $D(n,x)$
Regular Coulomb wave functions
The Coulomb wave equation for a charged particle with arbitrary angular momentum and charge is given by
\[ \nabla^2\psi +\left( k^2-\frac{2\mu}{\hbar^2}V(r)\right)\psi = 0,\]
where $\mu$ is the reduced mass of the system. The radial wave function $u(r)$ satisfies the following differential equation
\[ \frac{\text{d}^2 u_\ell}{\text{d}r^2}+\left( k^2-\frac{\ell(\ell+1)}{r^2}-\frac{2\mu}{\hbar^2}\frac{Ze^2}{r}\right)u_\ell=0,\]
where $Z$ is the product of the charges. Two independent solutions can be found to this equation – these are called the regular and irregular Coulomb wave functions denoted $F_\ell(r)$ and $G_\ell(r)$ respectively. The regular Coulomb wave function $F_\ell(r)$ is a real function that vanishes at $r=0$ and the behaviour of the function is described using a parameter $\eta$ which describes how strongly the Coulomb interaction is
\[ \eta = \frac{Zmc\alpha }{\hbar k},\]
where $m$ is the mass of the particle, $k$ is the wave number and $\alpha$ is the fine structure constant. The solution to is given by
\[ F_\ell(\eta,kr) = C_\ell (\eta) (kr)^{\ell+1}\text{e}^{-ikr} {}_1 F_1(\ell+1-i\eta,2\ell+2,2ikr),\]
where ${}_1F_1(kr)$ is a confluent hypergeometric function and $C_\ell(\eta)$ is a normalization constant given by
\[ C_\ell(\eta) = \frac{2^\ell \text{e}^{-\pi\eta/2}|\Gamma(\ell+1+i\eta)|}{(2\ell+1)!},\]
where $\Gamma$ is the gamma function. For numerical purposes, it is useful to use the integral representation of the regular Coulomb wave function
\[ F_\ell(\eta,\rho) = \frac{\rho^{\ell+1}2^\ell e^{i\rho-(\pi\eta/2)}}{|\Gamma(\ell+1+i\eta)|} \int_0^1 e^{-2i\rho t}t^{\ell+i\eta}(1-t)^{\ell-i\eta} \, \text{d}t.\]
This implementation need the gamma function from SpecialFunctions.jl
using Plots, FewSpecialFunctions, LaTeXStrings
plot_font = "Computer Modern"
default(
fontfamily=plot_font,
linewidth=2.5,
framestyle=:box,
label=nothing,
grid=true,
palette=:tab10,
)
x = range(0,25,1000)
plot(x,regular_coulomb.(0,0.3,x), label=L"F_0(0.3,ρ)")
plot!(x,regular_coulomb.(0,-0.3,x), label=L"F_0(-0.3,ρ)")
xlabel!(L"ρ")
title!("Regular Coulomb Wave Functions")
Use a similar approach to plot the regular Coulomb functions for different a $\ell$
using Plots, FewSpecialFunctions, LaTeXStrings
plot_font = "Computer Modern"
default(
fontfamily=plot_font,
linewidth=2.5,
framestyle=:box,
label=nothing,
grid=true,
palette=:tab10,
)
x = range(0,25,1000)
plot(x,regular_coulomb.(1e-5,5,x), label=L"F_0(5,ρ)")
plot!(x,regular_coulomb.(1,5,x), label=L"F_1(5,ρ)")
plot!(x,regular_coulomb.(2,5,x), label=L"F_2(5,ρ)")
plot!(x,regular_coulomb.(3,5,x), label=L"F_3(5,ρ)")
title!("Regular Coulomb Wave Functions")
xlabel!(L"ρ")
FewSpecialFunctions.regular_coulomb
— Functionregular_coulomb(ℓ,η,ρ)
Regular Coulomb wave function ℓ is the order(non-negative integer), η is the charge (real parameter) and ρ is the radial coordinate (non-negative real variable).
returns the value F_ℓ(η,ρ)
Struve functions
The Struve functions are solutions of the non-homogeneous Bessel's differential equation
\[ x^2 \frac{\text{d}^2 y}{\text{d}x^2} + x \frac{\text{d}y}{\text{d}x}+(x^2-\alpha^2)y = \frac{4(x/2)^{\alpha+1}}{\sqrt{\pi}\Gamma(\alpha+1/2)}\]
The Struve functions are implemented using the following integral representation
\[ \mathbf{H}_\nu(z) = \frac{2(z/2)^\nu}{\sqrt{\pi}\Gamma(\nu+1/2)} \int_0^1 (1-t)^{{\nu-1/2}}\sin(zt) \, \text{d}t\]
And
\[ \mathbf{H}_\nu(z) = \frac{2(z/2)^\nu}{\sqrt{\pi}\Gamma(\nu+1/2)} \int_0^{\pi/2} \sin(z\cos(\theta)) \sin^{2\nu}(\theta) \, \text{d}\theta\]
Here is an example
using Plots, FewSpecialFunctions, LaTeXStrings
plot_font = "Computer Modern"
default(
fontfamily=plot_font,
linewidth=2.5,
framestyle=:box,
label=nothing,
grid=true,
palette=:tab10,
)
x = range(-5,5,1000)
plot(x,Struve.(0,x),label=L"H_0(x)")
plot!(x,Struve.(1,x),label=L"H_1(x)")
plot!(x,Struve.(2,x),label=L"H_2(x)")
plot!(x,Struve.(3,x),label=L"H_3(x)")
plot!(x,Struve.(4,x),label=L"H_4(x)")
plot!(x,Struve.(5,x),label=L"H_5(x)")
xlabel!(L"x")
title!("Struve Functions")
FewSpecialFunctions.Struve
— FunctionStruve(ν::Number,z::Number,min_tol=1e-15)
Fresnel functions
using Plots, FewSpecialFunctions, LaTeXStrings
plot_font = "Computer Modern"
default(
fontfamily=plot_font,
linewidth=2.5,
framestyle=:box,
label=nothing,
grid=true,
palette=:tab10,
)
x = range(-25,25,5000)
plot(x,Fresnel_C_integral.(x),label=L"C(x)")
plot!(x,Fresnel_C_err.(x), ls=:dash, lw=1.5, label=L"\tilde{C}(x)")
title!("Fresnel Integral")
xlabel!(L"x")
and
using Plots, FewSpecialFunctions, LaTeXStrings
plot_font = "Computer Modern"
default(
fontfamily=plot_font,
linewidth=2.5,
framestyle=:box,
label=nothing,
grid=true,
palette=:tab10,
)
x = range(-25,25,5000)
plot(x,Fresnel_S_integral.(x),label=L"S(x)")
plot!(x,Fresnel_S_err.(x), ls=:dash, lw=1.5, label=L"\tilde{S}(x)")
title!("Fresnel Integral")
xlabel!(L"x")
FewSpecialFunctions.Fresnel_S_integral_pi
— FunctionFresnel_S_integral_pi(x)
The Fresnel function S(z) using the definition in Handbook of Mathematical Functions: Abramowitz and Stegun, where
\[ S(z) = \int_0^x \cos(\pi t^2/2) dt\]
Returns the value $S(x)$
FewSpecialFunctions.Fresnel_C_integral_pi
— FunctionFresnel_C_integral_pi(x)
The Fresnel function C(z) using the definition in Handbook of Mathematical Functions: Abramowitz and Stegun, where
\[ C(z) = \int_0^x \sin(\pi t^2/2) dt\]
Returns the value $C(x)$
FewSpecialFunctions.Fresnel_S_integral
— FunctionFresnel_S_integral(x)
The Fresnel function S(z) using the definition wiki
\[ S(z) = \int_0^x \sin(t^2) dt\]
Returns the value $S(x)$
FewSpecialFunctions.Fresnel_C_integral
— FunctionFresnel_C_integral(x)
The Fresnel function C(z) using the definition wiki
\[ C(z) = \int_0^x \cos(t^2) dt\]
Returns the value $C(x)$
FewSpecialFunctions.Fresnel_S_err
— FunctionFresnel_S_err(x)
The Fresnel function S(z) using the definition wiki and the error function.
\[S(z) = \sqrt{\frac{\pi}{2}} \frac{1+i}{4} \left[ \text{erf} \left(\frac{1+i}{\sqrt{2}}z \right) - i \text{erf} \left(\frac{1-i}{\sqrt{2}}z \right]\]
Returns the value $S(x)$
FewSpecialFunctions.Fresnel_C_err
— FunctionFresnel_C_err(x)
The Fresnel function C(z) using the definition wiki and the error function.
\[C(z) = \sqrt{\frac{\pi}{2}} \frac{1-i}{4}\left[ \text{erf}\left(\frac{1+i}{\sqrt{2}}z \right) + i \text{erf}\left(\frac{1-i}{\sqrt{2}}z\right]\]
Returns the value $C(x)$
Benchmarks
Using the integral approach
using FewSpecialFunctions,BenchmarkTools
x = range(0,150,1000)
@benchmark Fresnel_C_err.($x)
BenchmarkTools.Trial: 10000 samples with 1 evaluation.
Range (min … max): 98.750 μs … 251.708 μs ┊ GC (min … max): 0.00% … 0.00%
Time (median): 99.916 μs ┊ GC (median): 0.00%
Time (mean ± σ): 102.056 μs ± 10.531 μs ┊ GC (mean ± σ): 0.00% ± 0.00%
█▇▅▃▃▁▁▂▂▁ ▁ ▂
████████████████▇▇▆▆▆▆▅▅▃▄▅▃▄▅▅▁▅▅▅▄▅▅▅▅▅▅▆▄▅▅▅▃▃▅▄▃▄▄▅▅▄▄▁▄▄ █
98.8 μs Histogram: log(frequency) by time 160 μs <
Memory estimate: 7.94 KiB, allocs estimate: 1.
Using the error function
using FewSpecialFunctions,BenchmarkTools
@benchmark Fresnel_C_integral.($x)
BenchmarkTools.Trial: 6 samples with 1 evaluation.
Range (min … max): 896.303 ms … 983.415 ms ┊ GC (min … max): 0.99% … 0.94%
Time (median): 913.392 ms ┊ GC (median): 0.92%
Time (mean ± σ): 928.925 ms ± 37.389 ms ┊ GC (mean ± σ): 0.79% ± 0.24%
██ █ █ █ █
██▁▁▁▁▁█▁▁▁▁▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█▁▁▁▁▁▁▁▁▁█ ▁
896 ms Histogram: frequency by time 983 ms <
Memory estimate: 160.72 MiB, allocs estimate: 5915.