SDDSlib
Loading...
Searching...
No Matches
k23.c File Reference

Provides a function to compute the Modified Bessel Function of the Second Kind K_{2/3}(z). More...

#include "mdb.h"
#include "constants.h"
#include <math.h>

Go to the source code of this file.

Macros

#define A_LIM   10.1
 
#define EPS1   1.0e-12
 
#define EPS2   1.0e-8
 
#define GAMMA_OF_NY   1.354117939426400463
 
#define NY   2.0 / 3.0
 

Functions

double k23 (double z)
 Compute the Modified Bessel Function of the Second Kind K_{2/3}(z).
 

Detailed Description

Provides a function to compute the Modified Bessel Function of the Second Kind K_{2/3}(z).

This file implements k23(), which calculates the Modified Bessel Function K_{2/3}(z) over a range of input values. It uses a series expansion for smaller arguments and an asymptotic expansion for larger arguments, referencing Abramowitz & Stegun and based on Roger Dejus's original Fortran code k23.f.

License
This file is distributed under the terms of the Software License Agreement found in the file LICENSE included with this distribution.
Author
R. Dejus, H. Shang, R. Soliday

Definition in file k23.c.

Macro Definition Documentation

◆ A_LIM

#define A_LIM   10.1

Definition at line 23 of file k23.c.

◆ EPS1

#define EPS1   1.0e-12

Definition at line 24 of file k23.c.

◆ EPS2

#define EPS2   1.0e-8

Definition at line 25 of file k23.c.

◆ GAMMA_OF_NY

#define GAMMA_OF_NY   1.354117939426400463

Definition at line 26 of file k23.c.

◆ NY

#define NY   2.0 / 3.0

Definition at line 27 of file k23.c.

Function Documentation

◆ k23()

double k23 ( double z)

Compute the Modified Bessel Function of the Second Kind K_{2/3}(z).

This function calculates K_{2/3}(z) for inputs approximately in the range 0.0 < z < 60.0. For z < A_LIM, it applies a series expansion (Abramowitz & Stegun Eq. 9.6.2 and 9.6.10). For z ≥ A_LIM, it uses an asymptotic expansion (Eq. 9.7.2). The method is adapted from Roger Dejus’s code, taking into account precomputed gamma function values and ensuring numerical stability within specified tolerances (EPS1 and EPS2).

Parameters
zThe input value for which K_{2/3}(z) is evaluated.
Returns
The computed K_{2/3}(z).

Factorial of (-ny)

Definition at line 41 of file k23.c.

41 {
42 double c1, c2, zs, ny_fac, neg_ny_fac, zm, zp, pm, pp, term, sum, ze, za, mu, pa;
43 static double e2;
44 long k;
45
46 if (z < A_LIM) {
47 /* series expansion*/
48 c1 = PI / 2.0 / sin(PI * NY);
49 c2 = 2 * c1;
50 zs = z * z / 4.0;
51
52 ny_fac = NY * GAMMA_OF_NY; /* ! Factorial of (+ny)*/
53 neg_ny_fac = c2 / GAMMA_OF_NY; /*! Factorial of (-ny)*/
54 e2 = pow(z / 2.0, NY);
55 zm = 1 / e2 / neg_ny_fac;
56 zp = e2 / ny_fac;
57 /* first term */
58 pm = pp = 1.0;
59 sum = term = c1 * (pm * zm - pp * zp);
60 k = 0;
61 while (fabs(term) > EPS1 * sum) {
62 k = k + 1;
63 pm = pm * zs / (k * (k - NY));
64 pp = pp * zs / (k * (k + NY));
65 term = c1 * (pm * zm - pp * zp);
66 sum += term;
67 }
68 } else {
69 ze = sqrt(PI / 2.0 / z) * exp(-z);
70 za = 1.0 / (8.0 * z);
71 mu = 4.0 * NY * NY;
72 /* first term */
73 pa = 1.0;
74 sum = term = pa * ze;
75 /* Additional terms */
76 k = 0;
77 while (fabs(term) > EPS2 * sum) {
78 k = k + 1;
79 pa = pa * za * (mu - (2 * k - 1) * (2 * k - 1)) / k;
80 term = pa * ze;
81 sum += term;
82 }
83 }
84 return sum;
85}