ESS_GUIESS_GUI_DocsESS_GUI_batch_fittingESS_GUI_bumps_abstractionESS_GUI_iss1116ESS_GUI_iss879ESS_GUI_iss959ESS_GUI_openclESS_GUI_orderingESS_GUI_sync_sascalccostrafo411magnetic_scattrelease-4.1.1release-4.1.2release-4.2.2release_4.0.1ticket-1009ticket-1094-headlessticket-1242-2d-resolutionticket-1243ticket-1249ticket885unittest-saveload
Last change
on this file since c95a1a5 was
79492222,
checked in by krzywon, 10 years ago
|
Changed the file and folder names to remove all SANS references.
|
-
Property mode set to
100644
|
File size:
2.0 KB
|
Line | |
---|
1 | /* jn.c |
---|
2 | * |
---|
3 | * Bessel function of integer order |
---|
4 | * |
---|
5 | * |
---|
6 | * |
---|
7 | * SYNOPSIS: |
---|
8 | * |
---|
9 | * int n; |
---|
10 | * double x, y, jn(); |
---|
11 | * |
---|
12 | * y = jn( n, x ); |
---|
13 | * |
---|
14 | * |
---|
15 | * |
---|
16 | * DESCRIPTION: |
---|
17 | * |
---|
18 | * Returns Bessel function of order n, where n is a |
---|
19 | * (possibly negative) integer. |
---|
20 | * |
---|
21 | * The ratio of jn(x) to j0(x) is computed by backward |
---|
22 | * recurrence. First the ratio jn/jn-1 is found by a |
---|
23 | * continued fraction expansion. Then the recurrence |
---|
24 | * relating successive orders is applied until j0 or j1 is |
---|
25 | * reached. |
---|
26 | * |
---|
27 | * If n = 0 or 1 the routine for j0 or j1 is called |
---|
28 | * directly. |
---|
29 | * |
---|
30 | * |
---|
31 | * |
---|
32 | * ACCURACY: |
---|
33 | * |
---|
34 | * Absolute error: |
---|
35 | * arithmetic range # trials peak rms |
---|
36 | * DEC 0, 30 5500 6.9e-17 9.3e-18 |
---|
37 | * IEEE 0, 30 5000 4.4e-16 7.9e-17 |
---|
38 | * |
---|
39 | * |
---|
40 | * Not suitable for large n or x. Use jv() instead. |
---|
41 | * |
---|
42 | */ |
---|
43 | |
---|
44 | /* jn.c |
---|
45 | Cephes Math Library Release 2.8: June, 2000 |
---|
46 | Copyright 1984, 1987, 2000 by Stephen L. Moshier |
---|
47 | */ |
---|
48 | #include "mconf.h" |
---|
49 | #ifdef ANSIPROT |
---|
50 | extern double fabs ( double ); |
---|
51 | extern double j0 ( double ); |
---|
52 | extern double j1 ( double ); |
---|
53 | #else |
---|
54 | double fabs(), j0(), j1(); |
---|
55 | #endif |
---|
56 | extern double MACHEP; |
---|
57 | |
---|
58 | double jn( n, x ) |
---|
59 | int n; |
---|
60 | double x; |
---|
61 | { |
---|
62 | double pkm2, pkm1, pk, xk, r, ans; |
---|
63 | int k, sign; |
---|
64 | |
---|
65 | if( n < 0 ) |
---|
66 | { |
---|
67 | n = -n; |
---|
68 | if( (n & 1) == 0 ) /* -1**n */ |
---|
69 | sign = 1; |
---|
70 | else |
---|
71 | sign = -1; |
---|
72 | } |
---|
73 | else |
---|
74 | sign = 1; |
---|
75 | |
---|
76 | if( x < 0.0 ) |
---|
77 | { |
---|
78 | if( n & 1 ) |
---|
79 | sign = -sign; |
---|
80 | x = -x; |
---|
81 | } |
---|
82 | |
---|
83 | if( n == 0 ) |
---|
84 | return( sign * j0(x) ); |
---|
85 | if( n == 1 ) |
---|
86 | return( sign * j1(x) ); |
---|
87 | if( n == 2 ) |
---|
88 | return( sign * (2.0 * j1(x) / x - j0(x)) ); |
---|
89 | |
---|
90 | if( x < MACHEP ) |
---|
91 | return( 0.0 ); |
---|
92 | |
---|
93 | /* continued fraction */ |
---|
94 | #ifdef DEC |
---|
95 | k = 56; |
---|
96 | #else |
---|
97 | k = 53; |
---|
98 | #endif |
---|
99 | |
---|
100 | pk = 2 * (n + k); |
---|
101 | ans = pk; |
---|
102 | xk = x * x; |
---|
103 | |
---|
104 | do |
---|
105 | { |
---|
106 | pk -= 2.0; |
---|
107 | ans = pk - (xk/ans); |
---|
108 | } |
---|
109 | while( --k > 0 ); |
---|
110 | ans = x/ans; |
---|
111 | |
---|
112 | /* backward recurrence */ |
---|
113 | |
---|
114 | pk = 1.0; |
---|
115 | pkm1 = 1.0/ans; |
---|
116 | k = n-1; |
---|
117 | r = 2 * k; |
---|
118 | |
---|
119 | do |
---|
120 | { |
---|
121 | pkm2 = (pkm1 * r - pk * x) / x; |
---|
122 | pk = pkm1; |
---|
123 | pkm1 = pkm2; |
---|
124 | r -= 2.0; |
---|
125 | } |
---|
126 | while( --k > 0 ); |
---|
127 | |
---|
128 | if( fabs(pk) > fabs(pkm1) ) |
---|
129 | ans = j1(x)/pk; |
---|
130 | else |
---|
131 | ans = j0(x)/pkm1; |
---|
132 | return( sign * ans ); |
---|
133 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.