SDDSlib
Loading...
Searching...
No Matches
k13.c
Go to the documentation of this file.
1/**
2 * @file k13.c
3 * @brief Computes the Modified Bessel Function of the Second Kind K_{1/3}(z).
4 *
5 * This file provides the implementation of k13(), which computes the
6 * Modified Bessel Function of the Second Kind K_{1/3}(z) for a given input.
7 * It uses a series expansion for small arguments and an asymptotic expansion for
8 * larger arguments, referencing Abramowitz & Stegun and derived from Roger Dejus's k13.f code.
9 *
10 * @copyright
11 * - (c) 2002 The University of Chicago, as Operator of Argonne National Laboratory.
12 * - (c) 2002 The Regents of the University of California, as Operator of Los Alamos National Laboratory.
13 *
14 * @license
15 * This file is distributed under the terms of the Software License Agreement
16 * found in the file LICENSE included with this distribution.
17 *
18 * @author R. Dejus, H. Shang, R. Soliday
19 */
20
21#include "mdb.h"
22#include "constants.h"
23#include "math.h"
24
25#define A_LIM 10.1
26#define EPS1 1.0e-12
27#define EPS2 1.0e-8
28#define GAMMA_OF_NY 2.678938534707747898
29#define NY 1.0 / 3.0
30
31/**
32 * @brief Compute the Modified Bessel Function of the Second Kind K_{1/3}(z).
33 *
34 * This function calculates K_{1/3}(z) for inputs in the approximate range 0.0 < z < 60.0.
35 * For smaller z (z < A_LIM), it uses a series expansion, while for larger z,
36 * it employs an asymptotic expansion. The method and constants are adapted from
37 * the original Fortran implementation by Roger Dejus and mathematical formulas
38 * from Abramowitz & Stegun.
39 *
40 * @param z The input value for which K_{1/3}(z) is evaluated.
41 * @return The computed value of the Modified Bessel Function K_{1/3}(z).
42 */
43double k13(double z) {
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}
double k13(double z)
Compute the Modified Bessel Function of the Second Kind K_{1/3}(z).
Definition k13.c:43