[3936ad3] | 1 | /* j1.c |
---|
| 2 | * |
---|
| 3 | * Bessel function of order one |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * |
---|
| 7 | * SYNOPSIS: |
---|
| 8 | * |
---|
| 9 | * double x, y, j1(); |
---|
| 10 | * |
---|
| 11 | * y = j1( x ); |
---|
| 12 | * |
---|
| 13 | * |
---|
| 14 | * |
---|
| 15 | * DESCRIPTION: |
---|
| 16 | * |
---|
| 17 | * Returns Bessel function of order one of the argument. |
---|
| 18 | * |
---|
| 19 | * The domain is divided into the intervals [0, 8] and |
---|
| 20 | * (8, infinity). In the first interval a 24 term Chebyshev |
---|
| 21 | * expansion is used. In the second, the asymptotic |
---|
| 22 | * trigonometric representation is employed using two |
---|
| 23 | * rational functions of degree 5/5. |
---|
| 24 | * |
---|
| 25 | * |
---|
| 26 | * |
---|
| 27 | * ACCURACY: |
---|
| 28 | * |
---|
| 29 | * Absolute error: |
---|
| 30 | * arithmetic domain # trials peak rms |
---|
| 31 | * DEC 0, 30 10000 4.0e-17 1.1e-17 |
---|
| 32 | * IEEE 0, 30 30000 2.6e-16 1.1e-16 |
---|
| 33 | * |
---|
| 34 | * |
---|
| 35 | */ |
---|
| 36 | |
---|
| 37 | /* |
---|
| 38 | Cephes Math Library Release 2.8: June, 2000 |
---|
| 39 | Copyright 1984, 1987, 1989, 2000 by Stephen L. Moshier |
---|
| 40 | */ |
---|
[fad5dc1] | 41 | |
---|
[3f8584a2] | 42 | #if FLOAT_SIZE>4 |
---|
| 43 | //Cephes double pression function |
---|
[c8902ac] | 44 | double cephes_j1(double x); |
---|
[1596de3] | 45 | |
---|
[0b05c24] | 46 | constant double RPJ1[8] = { |
---|
| 47 | -8.99971225705559398224E8, |
---|
| 48 | 4.52228297998194034323E11, |
---|
| 49 | -7.27494245221818276015E13, |
---|
| 50 | 3.68295732863852883286E15, |
---|
| 51 | 0.0, |
---|
| 52 | 0.0, |
---|
| 53 | 0.0, |
---|
| 54 | 0.0 }; |
---|
| 55 | |
---|
| 56 | constant double RQJ1[8] = { |
---|
| 57 | 6.20836478118054335476E2, |
---|
| 58 | 2.56987256757748830383E5, |
---|
| 59 | 8.35146791431949253037E7, |
---|
| 60 | 2.21511595479792499675E10, |
---|
| 61 | 4.74914122079991414898E12, |
---|
| 62 | 7.84369607876235854894E14, |
---|
| 63 | 8.95222336184627338078E16, |
---|
| 64 | 5.32278620332680085395E18 |
---|
| 65 | }; |
---|
| 66 | |
---|
| 67 | constant double PPJ1[8] = { |
---|
| 68 | 7.62125616208173112003E-4, |
---|
| 69 | 7.31397056940917570436E-2, |
---|
| 70 | 1.12719608129684925192E0, |
---|
| 71 | 5.11207951146807644818E0, |
---|
| 72 | 8.42404590141772420927E0, |
---|
| 73 | 5.21451598682361504063E0, |
---|
| 74 | 1.00000000000000000254E0, |
---|
| 75 | 0.0} ; |
---|
| 76 | |
---|
| 77 | |
---|
| 78 | constant double PQJ1[8] = { |
---|
| 79 | 5.71323128072548699714E-4, |
---|
| 80 | 6.88455908754495404082E-2, |
---|
| 81 | 1.10514232634061696926E0, |
---|
| 82 | 5.07386386128601488557E0, |
---|
| 83 | 8.39985554327604159757E0, |
---|
| 84 | 5.20982848682361821619E0, |
---|
| 85 | 9.99999999999999997461E-1, |
---|
| 86 | 0.0 }; |
---|
| 87 | |
---|
| 88 | constant double QPJ1[8] = { |
---|
| 89 | 5.10862594750176621635E-2, |
---|
| 90 | 4.98213872951233449420E0, |
---|
| 91 | 7.58238284132545283818E1, |
---|
| 92 | 3.66779609360150777800E2, |
---|
| 93 | 7.10856304998926107277E2, |
---|
| 94 | 5.97489612400613639965E2, |
---|
| 95 | 2.11688757100572135698E2, |
---|
| 96 | 2.52070205858023719784E1 }; |
---|
| 97 | |
---|
| 98 | constant double QQJ1[8] = { |
---|
| 99 | 7.42373277035675149943E1, |
---|
| 100 | 1.05644886038262816351E3, |
---|
| 101 | 4.98641058337653607651E3, |
---|
| 102 | 9.56231892404756170795E3, |
---|
| 103 | 7.99704160447350683650E3, |
---|
| 104 | 2.82619278517639096600E3, |
---|
| 105 | 3.36093607810698293419E2, |
---|
| 106 | 0.0 }; |
---|
| 107 | |
---|
[c8902ac] | 108 | double cephes_j1(double x) |
---|
[3f8584a2] | 109 | { |
---|
| 110 | |
---|
[eb2946f] | 111 | double w, z, p, q, xn, abs_x, sign_x; |
---|
[3f8584a2] | 112 | |
---|
| 113 | const double Z1 = 1.46819706421238932572E1; |
---|
| 114 | const double Z2 = 4.92184563216946036703E1; |
---|
| 115 | const double THPIO4 = 2.35619449019234492885; |
---|
| 116 | const double SQ2OPI = 0.79788456080286535588; |
---|
| 117 | |
---|
[eb2946f] | 118 | // 2017-05-18 PAK - mathematica and mpmath use J1(-x) = -J1(x) |
---|
| 119 | if (x < 0) { |
---|
| 120 | abs_x = -x; |
---|
| 121 | sign_x = -1.0; |
---|
| 122 | } else { |
---|
| 123 | abs_x = x; |
---|
| 124 | sign_x = 1.0; |
---|
| 125 | } |
---|
[3f8584a2] | 126 | |
---|
[eb2946f] | 127 | if( abs_x <= 5.0 ) { |
---|
| 128 | z = abs_x * abs_x; |
---|
[3f8584a2] | 129 | w = polevl( z, RPJ1, 3 ) / p1evl( z, RQJ1, 8 ); |
---|
[eb2946f] | 130 | w = w * abs_x * (z - Z1) * (z - Z2); |
---|
| 131 | return( sign_x * w ); |
---|
[3f8584a2] | 132 | } |
---|
| 133 | |
---|
[eb2946f] | 134 | w = 5.0/abs_x; |
---|
[3f8584a2] | 135 | z = w * w; |
---|
| 136 | p = polevl( z, PPJ1, 6)/polevl( z, PQJ1, 6 ); |
---|
| 137 | q = polevl( z, QPJ1, 7)/p1evl( z, QQJ1, 7 ); |
---|
[eb2946f] | 138 | xn = abs_x - THPIO4; |
---|
[3f8584a2] | 139 | |
---|
| 140 | double sn, cn; |
---|
| 141 | SINCOS(xn, sn, cn); |
---|
| 142 | p = p * cn - w * q * sn; |
---|
| 143 | |
---|
[eb2946f] | 144 | return( sign_x * p * SQ2OPI / sqrt(abs_x) ); |
---|
[3f8584a2] | 145 | } |
---|
| 146 | |
---|
| 147 | #else |
---|
| 148 | //Single precission version of cephes |
---|
[c8902ac] | 149 | float cephes_j1f(float x); |
---|
[1596de3] | 150 | |
---|
[3f8584a2] | 151 | constant float JPJ1[8] = { |
---|
[0b05c24] | 152 | -4.878788132172128E-009, |
---|
| 153 | 6.009061827883699E-007, |
---|
| 154 | -4.541343896997497E-005, |
---|
| 155 | 1.937383947804541E-003, |
---|
| 156 | -3.405537384615824E-002, |
---|
| 157 | 0.0, |
---|
| 158 | 0.0, |
---|
| 159 | 0.0 |
---|
| 160 | }; |
---|
| 161 | |
---|
[3f8584a2] | 162 | constant float MO1J1[8] = { |
---|
[0b05c24] | 163 | 6.913942741265801E-002, |
---|
| 164 | -2.284801500053359E-001, |
---|
| 165 | 3.138238455499697E-001, |
---|
| 166 | -2.102302420403875E-001, |
---|
| 167 | 5.435364690523026E-003, |
---|
| 168 | 1.493389585089498E-001, |
---|
| 169 | 4.976029650847191E-006, |
---|
| 170 | 7.978845453073848E-001 |
---|
| 171 | }; |
---|
| 172 | |
---|
[3f8584a2] | 173 | constant float PH1J1[8] = { |
---|
[0b05c24] | 174 | -4.497014141919556E+001, |
---|
| 175 | 5.073465654089319E+001, |
---|
| 176 | -2.485774108720340E+001, |
---|
| 177 | 7.222973196770240E+000, |
---|
| 178 | -1.544842782180211E+000, |
---|
| 179 | 3.503787691653334E-001, |
---|
| 180 | -1.637986776941202E-001, |
---|
| 181 | 3.749989509080821E-001 |
---|
| 182 | }; |
---|
| 183 | |
---|
[eb2946f] | 184 | float cephes_j1f(float xx) |
---|
[0278e3f] | 185 | { |
---|
[3936ad3] | 186 | |
---|
[eb2946f] | 187 | float x, w, z, p, q, xn; |
---|
[0a9d219] | 188 | |
---|
[3f8584a2] | 189 | const float Z1 = 1.46819706421238932572E1; |
---|
| 190 | const float THPIO4F = 2.35619449019234492885; /* 3*pi/4 */ |
---|
[0a9d219] | 191 | |
---|
| 192 | |
---|
[eb2946f] | 193 | // 2017-05-18 PAK - mathematica and mpmath use J1(-x) = -J1(x) |
---|
| 194 | x = xx; |
---|
| 195 | if( x < 0 ) |
---|
| 196 | x = -xx; |
---|
[0a9d219] | 197 | |
---|
[eb2946f] | 198 | if( x <= 2.0 ) { |
---|
| 199 | z = x * x; |
---|
| 200 | p = (z-Z1) * x * polevl( z, JPJ1, 4 ); |
---|
| 201 | return( xx < 0. ? -p : p ); |
---|
[3f8584a2] | 202 | } |
---|
[0a9d219] | 203 | |
---|
| 204 | q = 1.0/x; |
---|
| 205 | w = sqrt(q); |
---|
| 206 | |
---|
[95ce773] | 207 | p = w * polevl( q, MO1J1, 7); |
---|
[0a9d219] | 208 | w = q*q; |
---|
[95ce773] | 209 | xn = q * polevl( w, PH1J1, 7) - THPIO4F; |
---|
[eb2946f] | 210 | p = p * cos(xn + x); |
---|
[0a9d219] | 211 | |
---|
[eb2946f] | 212 | return( xx < 0. ? -p : p ); |
---|
[fad5dc1] | 213 | } |
---|
[3f8584a2] | 214 | #endif |
---|
| 215 | |
---|
| 216 | #if FLOAT_SIZE>4 |
---|
[c8902ac] | 217 | #define sas_J1 cephes_j1 |
---|
[3f8584a2] | 218 | #else |
---|
[c8902ac] | 219 | #define sas_J1 cephes_j1f |
---|
[3f8584a2] | 220 | #endif |
---|
[fad5dc1] | 221 | |
---|
[95ce773] | 222 | //Finally J1c function that equals 2*J1(x)/x |
---|
[473a9f1] | 223 | double sas_2J1x_x(double x); |
---|
| 224 | double sas_2J1x_x(double x) |
---|
[0278e3f] | 225 | { |
---|
[19b9005] | 226 | return (x != 0.0 ) ? 2.0*sas_J1(x)/x : 1.0; |
---|
[95ce773] | 227 | } |
---|