[3936ad3] | 1 | /* j0.c |
---|
| 2 | * |
---|
| 3 | * Bessel function of order zero |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * |
---|
| 7 | * SYNOPSIS: |
---|
| 8 | * |
---|
| 9 | * double x, y, j0(); |
---|
| 10 | * |
---|
| 11 | * y = j0( x ); |
---|
| 12 | * |
---|
| 13 | * |
---|
| 14 | * |
---|
| 15 | * DESCRIPTION: |
---|
| 16 | * |
---|
| 17 | * Returns Bessel function of order zero of the argument. |
---|
| 18 | * |
---|
| 19 | * The domain is divided into the intervals [0, 5] and |
---|
| 20 | * (5, infinity). In the first interval the following rational |
---|
| 21 | * approximation is used: |
---|
| 22 | * |
---|
| 23 | * |
---|
| 24 | * 2 2 |
---|
| 25 | * (w - r ) (w - r ) P (w) / Q (w) |
---|
| 26 | * 1 2 3 8 |
---|
| 27 | * |
---|
| 28 | * 2 |
---|
| 29 | * where w = x and the two r's are zeros of the function. |
---|
| 30 | * |
---|
| 31 | * In the second interval, the Hankel asymptotic expansion |
---|
| 32 | * is employed with two rational functions of degree 6/6 |
---|
| 33 | * and 7/7. |
---|
| 34 | * |
---|
| 35 | * |
---|
| 36 | * |
---|
| 37 | * ACCURACY: |
---|
| 38 | * |
---|
| 39 | * Absolute error: |
---|
| 40 | * arithmetic domain # trials peak rms |
---|
| 41 | * DEC 0, 30 10000 4.4e-17 6.3e-18 |
---|
| 42 | * IEEE 0, 30 60000 4.2e-16 1.1e-16 |
---|
| 43 | * |
---|
| 44 | */ |
---|
| 45 | |
---|
| 46 | /* |
---|
| 47 | Cephes Math Library Release 2.8: June, 2000 |
---|
| 48 | Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier |
---|
| 49 | */ |
---|
| 50 | |
---|
| 51 | /* Note: all coefficients satisfy the relative error criterion |
---|
| 52 | * except YP, YQ which are designed for absolute error. */ |
---|
| 53 | |
---|
[0b05c24] | 54 | |
---|
| 55 | constant double PPJ0[8] = { |
---|
| 56 | 7.96936729297347051624E-4, |
---|
| 57 | 8.28352392107440799803E-2, |
---|
| 58 | 1.23953371646414299388E0, |
---|
| 59 | 5.44725003058768775090E0, |
---|
| 60 | 8.74716500199817011941E0, |
---|
| 61 | 5.30324038235394892183E0, |
---|
| 62 | 9.99999999999999997821E-1, |
---|
| 63 | 0.0 |
---|
| 64 | }; |
---|
| 65 | |
---|
| 66 | constant double PQJ0[8] = { |
---|
| 67 | 9.24408810558863637013E-4, |
---|
| 68 | 8.56288474354474431428E-2, |
---|
| 69 | 1.25352743901058953537E0, |
---|
| 70 | 5.47097740330417105182E0, |
---|
| 71 | 8.76190883237069594232E0, |
---|
| 72 | 5.30605288235394617618E0, |
---|
| 73 | 1.00000000000000000218E0, |
---|
| 74 | 0.0 |
---|
| 75 | }; |
---|
| 76 | |
---|
| 77 | constant double QPJ0[8] = { |
---|
| 78 | -1.13663838898469149931E-2, |
---|
| 79 | -1.28252718670509318512E0, |
---|
| 80 | -1.95539544257735972385E1, |
---|
| 81 | -9.32060152123768231369E1, |
---|
| 82 | -1.77681167980488050595E2, |
---|
| 83 | -1.47077505154951170175E2, |
---|
| 84 | -5.14105326766599330220E1, |
---|
| 85 | -6.05014350600728481186E0, |
---|
| 86 | }; |
---|
| 87 | |
---|
| 88 | constant double QQJ0[8] = { |
---|
| 89 | /* 1.00000000000000000000E0,*/ |
---|
| 90 | 6.43178256118178023184E1, |
---|
| 91 | 8.56430025976980587198E2, |
---|
| 92 | 3.88240183605401609683E3, |
---|
| 93 | 7.24046774195652478189E3, |
---|
| 94 | 5.93072701187316984827E3, |
---|
| 95 | 2.06209331660327847417E3, |
---|
| 96 | 2.42005740240291393179E2, |
---|
| 97 | }; |
---|
| 98 | |
---|
| 99 | constant double YPJ0[8] = { |
---|
| 100 | 1.55924367855235737965E4, |
---|
| 101 | -1.46639295903971606143E7, |
---|
| 102 | 5.43526477051876500413E9, |
---|
| 103 | -9.82136065717911466409E11, |
---|
| 104 | 8.75906394395366999549E13, |
---|
| 105 | -3.46628303384729719441E15, |
---|
| 106 | 4.42733268572569800351E16, |
---|
| 107 | -1.84950800436986690637E16, |
---|
| 108 | }; |
---|
| 109 | |
---|
| 110 | |
---|
| 111 | constant double YQJ0[7] = { |
---|
| 112 | /* 1.00000000000000000000E0,*/ |
---|
| 113 | 1.04128353664259848412E3, |
---|
| 114 | 6.26107330137134956842E5, |
---|
| 115 | 2.68919633393814121987E8, |
---|
| 116 | 8.64002487103935000337E10, |
---|
| 117 | 2.02979612750105546709E13, |
---|
| 118 | 3.17157752842975028269E15, |
---|
| 119 | 2.50596256172653059228E17, |
---|
| 120 | }; |
---|
| 121 | |
---|
| 122 | constant double RPJ0[8] = { |
---|
| 123 | -4.79443220978201773821E9, |
---|
| 124 | 1.95617491946556577543E12, |
---|
| 125 | -2.49248344360967716204E14, |
---|
| 126 | 9.70862251047306323952E15, |
---|
| 127 | 0.0, |
---|
| 128 | 0.0, |
---|
| 129 | 0.0, |
---|
| 130 | 0.0 |
---|
| 131 | }; |
---|
| 132 | |
---|
| 133 | constant double RQJ0[8] = { |
---|
| 134 | /* 1.00000000000000000000E0,*/ |
---|
| 135 | 4.99563147152651017219E2, |
---|
| 136 | 1.73785401676374683123E5, |
---|
| 137 | 4.84409658339962045305E7, |
---|
| 138 | 1.11855537045356834862E10, |
---|
| 139 | 2.11277520115489217587E12, |
---|
| 140 | 3.10518229857422583814E14, |
---|
| 141 | 3.18121955943204943306E16, |
---|
| 142 | 1.71086294081043136091E18, |
---|
| 143 | }; |
---|
| 144 | |
---|
| 145 | constant double MOJ0[8] = { |
---|
| 146 | -6.838999669318810E-002, |
---|
| 147 | 1.864949361379502E-001, |
---|
| 148 | -2.145007480346739E-001, |
---|
| 149 | 1.197549369473540E-001, |
---|
| 150 | -3.560281861530129E-003, |
---|
| 151 | -4.969382655296620E-002, |
---|
| 152 | -3.355424622293709E-006, |
---|
| 153 | 7.978845717621440E-001 |
---|
| 154 | }; |
---|
| 155 | |
---|
| 156 | constant double PHJ0[8] = { |
---|
| 157 | 3.242077816988247E+001, |
---|
| 158 | -3.630592630518434E+001, |
---|
| 159 | 1.756221482109099E+001, |
---|
| 160 | -4.974978466280903E+000, |
---|
| 161 | 1.001973420681837E+000, |
---|
| 162 | -1.939906941791308E-001, |
---|
| 163 | 6.490598792654666E-002, |
---|
| 164 | -1.249992184872738E-001 |
---|
| 165 | }; |
---|
| 166 | |
---|
| 167 | constant double JPJ0[8] = { |
---|
| 168 | -6.068350350393235E-008, |
---|
| 169 | 6.388945720783375E-006, |
---|
| 170 | -3.969646342510940E-004, |
---|
| 171 | 1.332913422519003E-002, |
---|
| 172 | -1.729150680240724E-001, |
---|
| 173 | 0.0, |
---|
| 174 | 0.0, |
---|
| 175 | 0.0 |
---|
| 176 | }; |
---|
| 177 | |
---|
[0278e3f] | 178 | double sas_J0(double x); |
---|
| 179 | double sas_J0(double x) |
---|
| 180 | { |
---|
[0a9d219] | 181 | |
---|
| 182 | //Cephes single precission |
---|
[07142f3] | 183 | #if FLOAT_SIZE>4 |
---|
[3936ad3] | 184 | double w, z, p, q, xn; |
---|
| 185 | |
---|
[95ce773] | 186 | //const double TWOOPI = 6.36619772367581343075535E-1; |
---|
[3936ad3] | 187 | const double SQ2OPI = 7.9788456080286535587989E-1; |
---|
| 188 | const double PIO4 = 7.85398163397448309616E-1; |
---|
| 189 | |
---|
[0a9d219] | 190 | const double DR1 = 5.78318596294678452118E0; |
---|
| 191 | const double DR2 = 3.04712623436620863991E1; |
---|
| 192 | |
---|
[3936ad3] | 193 | |
---|
| 194 | if( x < 0 ) |
---|
| 195 | x = -x; |
---|
| 196 | |
---|
| 197 | if( x <= 5.0 ) { |
---|
| 198 | z = x * x; |
---|
| 199 | if( x < 1.0e-5 ) |
---|
| 200 | return( 1.0 - z/4.0 ); |
---|
| 201 | |
---|
| 202 | p = (z - DR1) * (z - DR2); |
---|
[95ce773] | 203 | p = p * polevl( z, RPJ0, 3)/p1evl( z, RQJ0, 8 ); |
---|
[3936ad3] | 204 | return( p ); |
---|
| 205 | } |
---|
| 206 | |
---|
| 207 | w = 5.0/x; |
---|
| 208 | q = 25.0/(x*x); |
---|
[95ce773] | 209 | p = polevl( q, PPJ0, 6)/polevl( q, PQJ0, 6 ); |
---|
| 210 | q = polevl( q, QPJ0, 7)/p1evl( q, QQJ0, 7 ); |
---|
[3936ad3] | 211 | xn = x - PIO4; |
---|
| 212 | |
---|
| 213 | double sn, cn; |
---|
| 214 | SINCOS(xn, sn, cn); |
---|
| 215 | p = p * cn - w * q * sn; |
---|
| 216 | |
---|
| 217 | return( p * SQ2OPI / sqrt(x) ); |
---|
[0a9d219] | 218 | //Cephes single precission |
---|
[07142f3] | 219 | #else |
---|
[0a9d219] | 220 | double xx, w, z, p, q, xn; |
---|
| 221 | |
---|
[95ce773] | 222 | //const double YZ1 = 0.43221455686510834878; |
---|
| 223 | //const double YZ2 = 22.401876406482861405; |
---|
| 224 | //const double YZ3 = 64.130620282338755553; |
---|
[0a9d219] | 225 | const double DR1 = 5.78318596294678452118; |
---|
| 226 | const double PIO4F = 0.7853981633974483096; |
---|
| 227 | |
---|
| 228 | if( x < 0 ) |
---|
| 229 | xx = -x; |
---|
| 230 | else |
---|
| 231 | xx = x; |
---|
| 232 | |
---|
| 233 | if( x <= 2.0 ) { |
---|
| 234 | z = xx * xx; |
---|
| 235 | if( x < 1.0e-3 ) |
---|
| 236 | return( 1.0 - 0.25*z ); |
---|
| 237 | |
---|
[95ce773] | 238 | p = (z-DR1) * polevl( z, JPJ0, 4); |
---|
[0a9d219] | 239 | return( p ); |
---|
| 240 | } |
---|
| 241 | |
---|
| 242 | q = 1.0/x; |
---|
[094e320] | 243 | w = sqrt(q); |
---|
[0a9d219] | 244 | |
---|
[95ce773] | 245 | p = w * polevl( q, MOJ0, 7); |
---|
[0a9d219] | 246 | w = q*q; |
---|
[95ce773] | 247 | xn = q * polevl( w, PHJ0, 7) - PIO4F; |
---|
[094e320] | 248 | p = p * cos(xn + xx); |
---|
[0a9d219] | 249 | return(p); |
---|
[07142f3] | 250 | #endif |
---|
| 251 | |
---|
[0a9d219] | 252 | } |
---|
[3936ad3] | 253 | |
---|