using System;
using System.Numerics;
namespace IStation.Numerics
{
///
/// This partial implementation of the SpecialFunctions class contains all methods related to the modified Bessel function.
///
public static partial class SpecialFunctions
{
///
/// Returns the Kelvin function of the first kind.
/// KelvinBe(nu, x) is given by BesselJ(0, j * sqrt(j) * x) where j = sqrt(-1).
/// KelvinBer(nu, x) and KelvinBei(nu, x) are the real and imaginary parts of the KelvinBe(nu, x)
///
/// the order of the the Kelvin function.
/// The value to compute the Kelvin function of.
/// The Kelvin function of the first kind.
public static Complex KelvinBe(double nu, double x)
{
Complex ISqrtI = new Complex(-Constants.Sqrt1Over2, Constants.Sqrt1Over2); // j * sqrt(j) = (-1)^(3/4) = (-1 + j)/sqrt(2)
return BesselJ(nu, ISqrtI * x);
}
///
/// Returns the Kelvin function ber.
/// KelvinBer(nu, x) is given by the real part of BesselJ(nu, j * sqrt(j) * x) where j = sqrt(-1).
///
/// the order of the the Kelvin function.
/// The value to compute the Kelvin function of.
/// The Kelvin function ber.
public static double KelvinBer(double nu, double x)
{
return KelvinBe(nu, x).Real;
}
///
/// Returns the Kelvin function ber.
/// KelvinBer(x) is given by the real part of BesselJ(0, j * sqrt(j) * x) where j = sqrt(-1).
/// KelvinBer(x) is equivalent to KelvinBer(0, x).
///
/// The value to compute the Kelvin function of.
/// The Kelvin function ber.
public static double KelvinBer(double x)
{
return KelvinBe(0, x).Real;
}
///
/// Returns the Kelvin function bei.
/// KelvinBei(nu, x) is given by the imaginary part of BesselJ(nu, j * sqrt(j) * x) where j = sqrt(-1).
///
/// the order of the the Kelvin function.
/// The value to compute the Kelvin function of.
/// The Kelvin function bei.
public static double KelvinBei(double nu, double x)
{
return KelvinBe(nu, x).Imaginary;
}
///
/// Returns the Kelvin function bei.
/// KelvinBei(x) is given by the imaginary part of BesselJ(0, j * sqrt(j) * x) where j = sqrt(-1).
/// KelvinBei(x) is equivalent to KelvinBei(0, x).
///
/// The value to compute the Kelvin function of.
/// The Kelvin function bei.
public static double KelvinBei(double x)
{
return KelvinBe(0, x).Imaginary;
}
///
/// Returns the derivative of the Kelvin function ber.
///
/// The order of the Kelvin function.
/// The value to compute the derivative of the Kelvin function of.
/// the derivative of the Kelvin function ber
public static double KelvinBerPrime(double nu, double x)
{
const double inv2Sqrt2 = 0.35355339059327376220042218105242451964241796884424; // 1/(2 * sqrt(2))
return inv2Sqrt2 * (-KelvinBer(nu - 1, x) + KelvinBer(nu + 1, x) - KelvinBei(nu - 1, x) + KelvinBei(nu + 1, x));
}
///
/// Returns the derivative of the Kelvin function ber.
///
/// The value to compute the derivative of the Kelvin function of.
/// The derivative of the Kelvin function ber.
public static double KelvinBerPrime(double x)
{
return KelvinBerPrime(0, x);
}
///
/// Returns the derivative of the Kelvin function bei.
///
/// The order of the Kelvin function.
/// The value to compute the derivative of the Kelvin function of.
/// the derivative of the Kelvin function bei.
public static double KelvinBeiPrime(double nu, double x)
{
const double inv2Sqrt2 = 0.35355339059327376220042218105242451964241796884424; // 1/(2 * sqrt(2))
return inv2Sqrt2 * (KelvinBer(nu - 1, x) - KelvinBer(nu + 1, x) - KelvinBei(nu - 1, x) + KelvinBei(nu + 1, x));
}
///
/// Returns the derivative of the Kelvin function bei.
///
/// The value to compute the derivative of the Kelvin function of.
/// The derivative of the Kelvin function bei.
public static double KelvinBeiPrime(double x)
{
return KelvinBeiPrime(0, x);
}
///
/// Returns the Kelvin function of the second kind
/// KelvinKe(nu, x) is given by Exp(-nu * pi * j / 2) * BesselK(nu, x * sqrt(j)) where j = sqrt(-1).
/// KelvinKer(nu, x) and KelvinKei(nu, x) are the real and imaginary parts of the KelvinBe(nu, x)
///
/// The order of the Kelvin function.
/// The value to calculate the kelvin function of,
///
public static Complex KelvinKe(double nu, double x)
{
Complex PiIOver2 = new Complex(0.0, Constants.PiOver2); // pi * I / 2
Complex SqrtI = new Complex(Constants.Sqrt1Over2, Constants.Sqrt1Over2); // sqrt(j) = (-1)^(1/4) = (1 + j)/sqrt(2)
return Complex.Exp(-nu * PiIOver2) * BesselK(nu, SqrtI * x);
}
///
/// Returns the Kelvin function ker.
/// KelvinKer(nu, x) is given by the real part of Exp(-nu * pi * j / 2) * BesselK(nu, sqrt(j) * x) where j = sqrt(-1).
///
/// the order of the the Kelvin function.
/// The non-negative real value to compute the Kelvin function of.
/// The Kelvin function ker.
public static double KelvinKer(double nu, double x)
{
if (x <= 0.0)
{
throw new ArithmeticException();
}
return KelvinKe(nu, x).Real;
}
///
/// Returns the Kelvin function ker.
/// KelvinKer(x) is given by the real part of Exp(-nu * pi * j / 2) * BesselK(0, sqrt(j) * x) where j = sqrt(-1).
/// KelvinKer(x) is equivalent to KelvinKer(0, x).
///
/// The non-negative real value to compute the Kelvin function of.
/// The Kelvin function ker.
public static double KelvinKer(double x)
{
if (x <= 0.0)
{
throw new ArithmeticException();
}
return KelvinKe(0, x).Real;
}
///
/// Returns the Kelvin function kei.
/// KelvinKei(nu, x) is given by the imaginary part of Exp(-nu * pi * j / 2) * BesselK(nu, sqrt(j) * x) where j = sqrt(-1).
///
/// the order of the the Kelvin function.
/// The non-negative real value to compute the Kelvin function of.
/// The Kelvin function kei.
public static double KelvinKei(double nu, double x)
{
if (x <= 0.0)
{
throw new ArithmeticException();
}
return KelvinKe(nu, x).Imaginary;
}
///
/// Returns the Kelvin function kei.
/// KelvinKei(x) is given by the imaginary part of Exp(-nu * pi * j / 2) * BesselK(0, sqrt(j) * x) where j = sqrt(-1).
/// KelvinKei(x) is equivalent to KelvinKei(0, x).
///
/// The non-negative real value to compute the Kelvin function of.
/// The Kelvin function kei.
public static double KelvinKei(double x)
{
if (x <= 0.0)
{
throw new ArithmeticException();
}
return KelvinKe(0, x).Imaginary;
}
///
/// Returns the derivative of the Kelvin function ker.
///
/// The order of the Kelvin function.
/// The non-negative real value to compute the derivative of the Kelvin function of.
/// The derivative of the Kelvin function ker.
public static double KelvinKerPrime(double nu, double x)
{
if (x <= 0.0)
{
throw new ArithmeticException();
}
const double inv2Sqrt2 = 0.35355339059327376220042218105242451964241796884424; // 1/(2 * sqrt(2))
return inv2Sqrt2 * (-KelvinKer(nu - 1, x) + KelvinKer(nu + 1, x) - KelvinKei(nu - 1, x) + KelvinKei(nu + 1, x));
}
///
/// Returns the derivative of the Kelvin function ker.
///
/// The value to compute the derivative of the Kelvin function of.
/// The derivative of the Kelvin function ker.
public static double KelvinKerPrime(double x)
{
if (x <= 0.0)
{
throw new ArithmeticException();
}
return KelvinKerPrime(0, x);
}
///
/// Returns the derivative of the Kelvin function kei.
///
/// The order of the Kelvin function.
/// The value to compute the derivative of the Kelvin function of.
/// The derivative of the Kelvin function kei.
public static double KelvinKeiPrime(double nu, double x)
{
if (x <= 0.0)
{
throw new ArithmeticException();
}
const double inv2Sqrt2 = 0.35355339059327376220042218105242451964241796884424; // 1/(2 * sqrt(2))
return inv2Sqrt2 * (KelvinKer(nu - 1, x) - KelvinKer(nu + 1, x) - KelvinKei(nu - 1, x) + KelvinKei(nu + 1, x));
}
///
/// Returns the derivative of the Kelvin function kei.
///
/// The value to compute the derivative of the Kelvin function of.
/// The derivative of the Kelvin function kei.
public static double KelvinKeiPrime(double x)
{
if (x <= 0.0)
{
throw new ArithmeticException();
}
return KelvinKeiPrime(0, x);
}
}
}