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

Computes the Modified Bessel Function of the Second Kind K_{1/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   2.678938534707747898
 
#define NY   1.0 / 3.0
 

Functions

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

Detailed Description

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

This file provides the implementation of k13(), which computes the Modified Bessel Function of the Second Kind K_{1/3}(z) for a given input. It uses a series expansion for small arguments and an asymptotic expansion for larger arguments, referencing Abramowitz & Stegun and derived from Roger Dejus's k13.f code.

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 k13.c.

Macro Definition Documentation

◆ A_LIM

#define A_LIM   10.1

Definition at line 25 of file k13.c.

◆ EPS1

#define EPS1   1.0e-12

Definition at line 26 of file k13.c.

◆ EPS2

#define EPS2   1.0e-8

Definition at line 27 of file k13.c.

◆ GAMMA_OF_NY

#define GAMMA_OF_NY   2.678938534707747898

Definition at line 28 of file k13.c.

◆ NY

#define NY   1.0 / 3.0

Definition at line 29 of file k13.c.

Function Documentation

◆ k13()

double k13 ( double z)

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

This function calculates K_{1/3}(z) for inputs in the approximate range 0.0 < z < 60.0. For smaller z (z < A_LIM), it uses a series expansion, while for larger z, it employs an asymptotic expansion. The method and constants are adapted from the original Fortran implementation by Roger Dejus and mathematical formulas from Abramowitz & Stegun.

Parameters
zThe input value for which K_{1/3}(z) is evaluated.
Returns
The computed value of the Modified Bessel Function K_{1/3}(z).

Definition at line 43 of file k13.c.

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