i0.c
Go to the documentation of this file.
1 /* i0.c
2  *
3  * Modified Bessel function of order zero
4  *
5  *
6  *
7  * SYNOPSIS:
8  *
9  * double x, y, i0();
10  *
11  * y = i0( x );
12  *
13  *
14  *
15  * DESCRIPTION:
16  *
17  * Returns modified Bessel function of order zero of the
18  * argument.
19  *
20  * The function is defined as i0(x) = j0( ix ).
21  *
22  * The range is partitioned into the two intervals [0,8] and
23  * (8, infinity). Chebyshev polynomial expansions are employed
24  * in each interval.
25  *
26  *
27  *
28  * ACCURACY:
29  *
30  * Relative error:
31  * arithmetic domain # trials peak rms
32  * IEEE 0,30 30000 5.8e-16 1.4e-16
33  *
34  */
35  /* i0e.c
36  *
37  * Modified Bessel function of order zero,
38  * exponentially scaled
39  *
40  *
41  *
42  * SYNOPSIS:
43  *
44  * double x, y, i0e();
45  *
46  * y = i0e( x );
47  *
48  *
49  *
50  * DESCRIPTION:
51  *
52  * Returns exponentially scaled modified Bessel function
53  * of order zero of the argument.
54  *
55  * The function is defined as i0e(x) = exp(-|x|) j0( ix ).
56  *
57  *
58  *
59  * ACCURACY:
60  *
61  * Relative error:
62  * arithmetic domain # trials peak rms
63  * IEEE 0,30 30000 5.4e-16 1.2e-16
64  * See i0().
65  *
66  */
67 
68 /* i0.c */
69 
70 
71 /*
72  * Cephes Math Library Release 2.8: June, 2000
73  * Copyright 1984, 1987, 2000 by Stephen L. Moshier
74  */
75 
76 #include "mconf.h"
77 
78 /* Chebyshev coefficients for exp(-x) I0(x)
79  * in the interval [0,8].
80  *
81  * lim(x->0){ exp(-x) I0(x) } = 1.
82  */
83 static double A[] = {
84  -4.41534164647933937950E-18,
85  3.33079451882223809783E-17,
86  -2.43127984654795469359E-16,
87  1.71539128555513303061E-15,
88  -1.16853328779934516808E-14,
89  7.67618549860493561688E-14,
90  -4.85644678311192946090E-13,
91  2.95505266312963983461E-12,
92  -1.72682629144155570723E-11,
93  9.67580903537323691224E-11,
94  -5.18979560163526290666E-10,
95  2.65982372468238665035E-9,
96  -1.30002500998624804212E-8,
97  6.04699502254191894932E-8,
98  -2.67079385394061173391E-7,
99  1.11738753912010371815E-6,
100  -4.41673835845875056359E-6,
101  1.64484480707288970893E-5,
102  -5.75419501008210370398E-5,
103  1.88502885095841655729E-4,
104  -5.76375574538582365885E-4,
105  1.63947561694133579842E-3,
106  -4.32430999505057594430E-3,
107  1.05464603945949983183E-2,
108  -2.37374148058994688156E-2,
109  4.93052842396707084878E-2,
110  -9.49010970480476444210E-2,
111  1.71620901522208775349E-1,
112  -3.04682672343198398683E-1,
113  6.76795274409476084995E-1
114 };
115 
116 /* Chebyshev coefficients for exp(-x) sqrt(x) I0(x)
117  * in the inverted interval [8,infinity].
118  *
119  * lim(x->inf){ exp(-x) sqrt(x) I0(x) } = 1/sqrt(2pi).
120  */
121 static double B[] = {
122  -7.23318048787475395456E-18,
123  -4.83050448594418207126E-18,
124  4.46562142029675999901E-17,
125  3.46122286769746109310E-17,
126  -2.82762398051658348494E-16,
127  -3.42548561967721913462E-16,
128  1.77256013305652638360E-15,
129  3.81168066935262242075E-15,
130  -9.55484669882830764870E-15,
131  -4.15056934728722208663E-14,
132  1.54008621752140982691E-14,
133  3.85277838274214270114E-13,
134  7.18012445138366623367E-13,
135  -1.79417853150680611778E-12,
136  -1.32158118404477131188E-11,
137  -3.14991652796324136454E-11,
138  1.18891471078464383424E-11,
139  4.94060238822496958910E-10,
140  3.39623202570838634515E-9,
141  2.26666899049817806459E-8,
142  2.04891858946906374183E-7,
143  2.89137052083475648297E-6,
144  6.88975834691682398426E-5,
145  3.36911647825569408990E-3,
146  8.04490411014108831608E-1
147 };
148 
149 double i0(double x)
150 {
151  double y;
152 
153  if (x < 0)
154  x = -x;
155  if (x <= 8.0) {
156  y = (x / 2.0) - 2.0;
157  return (exp(x) * chbevl(y, A, 30));
158  }
159 
160  return (exp(x) * chbevl(32.0 / x - 2.0, B, 25) / sqrt(x));
161 
162 }
163 
164 
165 
166 
167 double i0e(double x)
168 {
169  double y;
170 
171  if (x < 0)
172  x = -x;
173  if (x <= 8.0) {
174  y = (x / 2.0) - 2.0;
175  return (chbevl(y, A, 30));
176  }
177 
178  return (chbevl(32.0 / x - 2.0, B, 25) / sqrt(x));
179 
180 }
i0e
double i0e(double x)
Definition: i0.c:167
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition: gnuplot_common_settings.hh:12
B
Definition: test_numpy_dtypes.cpp:299
exp
const EIGEN_DEVICE_FUNC ExpReturnType exp() const
Definition: ArrayCwiseUnaryOps.h:97
chbevl
double chbevl(double x, double array[], int n)
Definition: chbevl.c:63
A
Definition: test_numpy_dtypes.cpp:298
y
Scalar * y
Definition: level1_cplx_impl.h:124
i0
double i0(double x)
Definition: i0.c:149
mconf.h
ceres::sqrt
Jet< T, N > sqrt(const Jet< T, N > &f)
Definition: jet.h:418


gtsam
Author(s):
autogenerated on Thu Dec 19 2024 04:01:15