ADMB Documentation  -a65f1c97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
df1b2bessel.cpp
Go to the documentation of this file.
1 
7 #include <df1b2fun.h>
8 
9 #define ACC 40.0
10 #define BIGNO 1.0e10
11 #define BIGNI 1.0e-10
12 
14  df1b2variable ax,z;
15  df1b2variable xx,y,ans,ans1,ans2;
16  if (value(ax=fabs(x)) < 8.0) {
17  y=x*x;
18  ans1=57568490574.0+y*(-13362590354.0+y*(651619640.7+y*(-11214424.18+y*(77392.33017+y*(-184.9052456)))));
19  ans2=57568490411.0+y*(1029532985.0+y*(9494680.718+y*(59272.64853+y*(267.8532712+y*1.0))));
20  ans=ans1/ans2;
21  } else {
22  z=8.0/ax;
23  y=z*z;
24  xx=ax-0.785398164;
25  ans1=1.0+y*(-0.1098628627e-2+y*(0.2734510407e-4+y*(-0.2073370639e-5+y*0.2093887211e-6)));
26  ans2 = -0.1562499995e-1+y*(0.1430488765e-3+y*(-0.6911147651e-5+y*(0.7621095161e-6-y*0.934945152e-7)));
27  ans=sqrt(0.636619772/ax)*(cos(xx)*ans1-z*sin(xx)*ans2);
28  }
29  return ans;
30 }
31 
33 {
35  df1b2variable z;
36  df1b2variable xx,y,ans,ans1,ans2;
37  if (value(x) < 8.0) {
38  y=x*x;
39  ans1 = -2957821389.0+y*(7062834065.0+y*(-512359803.6+y*(10879881.29+y*(-86327.92757+y*228.4622733))));
40  ans2=40076544269.0+y*(745249964.8+y*(7189466.438+y*(47447.26470+y*(226.1030244+y*1.0))));
41  ans=(ans1/ans2)+0.636619772*bessj0(x)*log(x);
42  } else {
43  z=8.0/x;
44  y=z*z;
45  xx=x-0.785398164;
46  ans1=1.0+y*(-0.1098628627e-2+y*(0.2734510407e-4+y*(-0.2073370639e-5+y*0.2093887211e-6)));
47  ans2 = -0.1562499995e-1+y*(0.1430488765e-3+y*(-0.6911147651e-5+y*(0.7621095161e-6+y*(-0.934945152e-7))));
48  ans=sqrt(0.636619772/x)*(sin(xx)*ans1+z*cos(xx)*ans2);
49  }
50  return ans;
51 }
52 
54 {
55  df1b2variable ax,z;
56  df1b2variable xx,y,ans,ans1,ans2;
57  if (value(ax=fabs(x)) < 8.0) {
58  y=x*x;
59  ans1=x*(72362614232.0+y*(-7895059235.0+y*(242396853.1+y*(-2972611.439+y*(15704.48260+y*(-30.16036606))))));
60  ans2=144725228442.0+y*(2300535178.0+y*(18583304.74+y*(99447.43394+y*(376.9991397+y*1.0))));
61  ans=ans1/ans2;
62  } else {
63  z=8.0/ax;
64  y=z*z;
65  xx=ax-2.356194491;
66  ans1=1.0+y*(0.183105e-2+y*(-0.3516396496e-4+y*(0.2457520174e-5+y*(-0.240337019e-6))));
67  ans2=0.04687499995+y*(-0.2002690873e-3+y*(0.8449199096e-5+y*(-0.88228987e-6+y*0.105787412e-6)));
68  ans=sqrt(0.636619772/ax)*(cos(xx)*ans1-z*sin(xx)*ans2);
69  if (value(x) < 0.0) ans = -ans;
70  }
71  return ans;
72 }
73 
75 {
77  df1b2variable z;
78  df1b2variable xx,y,ans,ans1,ans2;
79  if (value(x) < 8.0) {
80  y=x*x;
81  ans1=x*(-0.4900604943e13+y*(0.1275274390e13+y*(-0.5153438139e11+y*(0.7349264551e9+y*(-0.4237922726e7+y*0.8511937935e4)))));
82  ans2=0.2499580570e14+y*(0.4244419664e12+y*(0.3733650367e10+y*(0.2245904002e8+y*(0.1020426050e6+y*(0.3549632885e3+y)))));
83  ans=(ans1/ans2)+0.636619772*(bessj1(x)*log(x)-1.0/x);
84  } else {
85  z=8.0/x;
86  y=z*z;
87  xx=x-2.356194491;
88  ans1=1.0+y*(0.183105e-2+y*(-0.3516396496e-4+y*(0.2457520174e-5+y*(-0.240337019e-6))));
89  ans2=0.04687499995+y*(-0.2002690873e-3+y*(0.8449199096e-5+y*(-0.88228987e-6+y*0.105787412e-6)));
90  ans=sqrt(0.636619772/x)*(sin(xx)*ans1+z*cos(xx)*ans2);
91  }
92  return ans;
93 }
94 
96 {
99  int j;
100  df1b2variable by,bym,byp,tox;
101  if (n < 2) cerr << "Index n less than 2 in bessy" << endl;
102  tox=2.0/x;
103  by=bessy1(x);
104  bym=bessy0(x);
105  for (j=1;j<n;j++) {
106  byp=j*tox*by-bym;
107  bym=by;
108  by=byp;
109  }
110  return by;
111 }
112 
114 {
117  int j,jsum,m;
118  df1b2variable ax,bj,bjm,bjp,sum,tox,ans;
119  if (n < 2) cerr << "Index n less than 2 in bessj" << endl;
120  ax=fabs(x);
121  if (value(ax) == 0.0)
122  return 0.0;
123  else if (value(ax) > (double) n) {
124  tox=2.0/ax;
125  bjm=bessj0(ax);
126  bj=bessj1(ax);
127  for (j=1;j<n;j++) {
128  bjp=j*tox*bj-bjm;
129  bjm=bj;
130  bj=bjp;
131  }
132  ans=bj;
133  } else {
134  tox = 2.0/ax;
135  m=2*((n+(int) sqrt(ACC*n))/2);
136  jsum=0;
137  bjp=0; ans=0; sum=0;
138  bj=1.0;
139  for (j=m;j>0;j--) {
140  bjm=j*tox*bj-bjp;
141  bjp=bj;
142  bj=bjm;
143  if (value(fabs(bj)) > BIGNO) {
144  bj *= BIGNI;
145  bjp *= BIGNI;
146  ans *= BIGNI;
147  sum *= BIGNI;
148  }
149  if (jsum) sum += bj;
150  jsum=!jsum;
151  if (j == n) ans=bjp;
152  }
153  sum=2.0*sum-bj;
154  ans /= sum;
155  }
156  return value(x) < 0.0 && (n & 1) ? -ans : ans;
157 }
158 
160 {
161  df1b2variable ax,ans;
162  df1b2variable y;
163  if (value(ax=fabs(x)) < 3.75) {
164  y=x/3.75;
165  y*=y;
166  ans=1.0+y*(3.5156229+y*(3.0899424+y*(1.2067492+y*(0.2659732+y*(0.360768e-1+y*0.45813e-2)))));
167  } else {
168  y=3.75/ax;
169  ans=(exp(ax)/sqrt(ax))*(0.39894228+y*(0.1328592e-1+y*(0.225319e-2+y*(-0.157565e-2+y*(0.916281e-2+y*(-0.2057706e-1+y*(0.2635537e-1+y*(-0.1647633e-1+y*0.392377e-2))))))));
170  }
171  return ans;
172 }
173 
175 {
177  df1b2variable y,ans;
178  if (value(x) <= 2.0) {
179  y=x*x/4.0;
180  ans=(-log(x/2.0)*bessi0(x))+(-0.57721566+y*(0.42278420+y*(0.23069756+y*(0.3488590e-1+y*(0.262698e-2+y*(0.10750e-3+y*0.74e-5))))));
181  } else {
182  y=2.0/x;
183  ans=(exp(-x)/sqrt(x))*(1.25331414+y*(-0.7832358e-1+y*(0.2189568e-1+y*(-0.1062446e-1+y*(0.587872e-2+y*(-0.251540e-2+y*0.53208e-3))))));
184  }
185  return ans;
186 }
187 
189 {
190  df1b2variable ax,ans;
191  df1b2variable y;
192  if (value(ax=fabs(x)) < 3.75) {
193  y=x/3.75;
194  y*=y;
195  ans=ax*(0.5+y*(0.87890594+y*(0.51498869+y*(0.15084934+y*(0.2658733e-1+y*(0.301532e-2+y*0.32411e-3))))));
196  } else {
197  y=3.75/ax;
198  ans=0.2282967e-1+y*(-0.2895312e-1+y*(0.1787654e-1-y*0.420059e-2));
199  ans=0.39894228+y*(-0.3988024e-1+y*(-0.362018e-2+y*(0.163801e-2+y*(-0.1031555e-1+y*ans))));
200  ans *= (exp(ax)/sqrt(ax));
201  }
202  return value(x) < 0.0 ? -ans : ans;
203 }
204 
206 {
208  df1b2variable y,ans;
209  if (value(x) <= 2.0) {
210  y=x*x/4.0;
211  ans=(log(x/2.0)*bessi1(x))+(1.0/x)*(1.0+y*(0.15443144+y*(-0.67278579+y*(-0.18156897+y*(-0.1919402e-1+y*(-0.110404e-2+y*(-0.4686e-4)))))));
212  } else {
213  y=2.0/x;
214  ans=(exp(-x)/sqrt(x))*(1.25331414+y*(0.23498619+y*(-0.3655620e-1+y*(0.1504268e-1+y*(-0.780353e-2+y*(0.325614e-2+y*(-0.68245e-3)))))));
215  }
216  return ans;
217 }
218 
220 {
223  int j;
224  df1b2variable bk,bkm,bkp,tox;
225  if (n < 2) cerr<<"Index n less than 2 in bessk"<<endl;
226  tox=2.0/x;
227  bkm=bessk0(x);
228  bk=bessk1(x);
229  for (j=1;j<n;j++) {
230  bkp=bkm+j*tox*bk;
231  bkm=bk;
232  bk=bkp;
233  }
234  return bk;
235 }
236 
238 {
240  int j;
241  df1b2variable bi,bim,bip,tox,ans;
242  if (n < 2) cerr<<"Index n less than 2 in bessi"<<endl;
243  if (value(x) == 0.0)
244  return 0.0;
245  else {
246  tox=2.0/fabs(x);
247  bip=0; ans=0;
248  bi=1.0;
249  for (j=2*(n+(int) sqrt(ACC*n));j>0;j--) {
250  bim=bip+j*tox*bi;
251  bip=bi;
252  bi=bim;
253  if (value(fabs(bi)) > BIGNO) {
254  ans *= BIGNI;
255  bi *= BIGNI;
256  bip *= BIGNI;
257  }
258  if (j == n) ans=bip;
259  }
260  ans *= bessi0(x)/bi;
261  return value(x) < 0.0 && (n & 1) ? -ans : ans;
262  }
263 }
264 
266  if(nu==0){
267  return bessi0(x);
268  }else{
269  if(nu==1){
270  return bessi1(x);
271  }else{
272  return bessi(nu,x);
273  }
274  }
275 }
276 
278  if(nu==0){
279  return bessk0(x);
280  }else{
281  if(nu==1){
282  return bessk1(x);
283  }else{
284  return bessk(nu,x);
285  }
286  }
287 }
288 
289 
291  if(nu==0){
292  return bessj0(x);
293  }else{
294  if(nu==1){
295  return bessj1(x);
296  }else{
297  return bessj(nu,x);
298  }
299  }
300 }
301 
303  if(nu==0){
304  return bessy0(x);
305  }else{
306  if(nu==1){
307  return bessy1(x);
308  }else{
309  return bessy(nu,x);
310  }
311  }
312 }
double bessi1(double x)
Definition: cbessel.cpp:190
double bessy1(double x)
Definition: cbessel.cpp:76
double besselY(double x, int nu)
Definition: cbessel.cpp:304
#define ACC
Author: Anders Nielsen Copyright (c) 2008-2012 Regents of the University of California.
Definition: df1b2bessel.cpp:9
#define x
double besselJ(double x, int nu)
Definition: cbessel.cpp:292
double sum(const d3_array &darray)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr.cpp:21
d3_array sin(const d3_array &arr3)
Returns d3_array results with computed sin from elements in arr3.
Definition: d3arr2a.cpp:43
df1_two_variable fabs(const df1_two_variable &x)
Definition: df12fun.cpp:891
double bessk(int n, double x)
Definition: cbessel.cpp:221
double besselI(double x, int nu)
Definition: cbessel.cpp:267
Description not yet available.
Definition: df1b2fun.h:266
double bessi0(double x)
Definition: cbessel.cpp:161
double bessk0(double x)
Definition: cbessel.cpp:176
prnstream & endl(prnstream &)
double besselK(double x, int nu)
Definition: cbessel.cpp:279
d3_array sqrt(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr2c.cpp:11
double bessj1(double x)
Definition: cbessel.cpp:55
double bessy(int n, double x)
Definition: cbessel.cpp:97
double bessj0(double x)
Definition: cbessel.cpp:15
d3_array exp(const d3_array &arr3)
Returns d3_array results with computed exp from elements in arr3.
Definition: d3arr2a.cpp:28
double bessi(int n, double x)
Definition: cbessel.cpp:239
#define BIGNO
Definition: df1b2bessel.cpp:10
double bessj(int n, double x)
Definition: cbessel.cpp:115
d3_array cos(const d3_array &arr3)
Returns d3_array results with computed cos from elements in arr3.
Definition: d3arr2a.cpp:58
Description not yet available.
#define BIGNI
Definition: df1b2bessel.cpp:11
dvector value(const df1_one_vector &v)
Definition: df11fun.cpp:69
double bessk1(double x)
Definition: cbessel.cpp:207
d3_array log(const d3_array &arr3)
Author: David Fournier Copyright (c) 2008-2012 Regents of the University of California.
Definition: d3arr2a.cpp:13
double bessy0(double x)
Definition: cbessel.cpp:34