Debian Codegraph @

external/gsl/gsl_specfunc__mathieu_radfunc.c

raw symbols SCIP
1 /* specfunc/mathieu_radfunc.c
2 *
3 * Copyright (C) 2002 Lowell Johnson
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19
20 /* Author: L. Johnson */
21
22 #include "gsl__config.h"
23 #include <stdlib.h>
24 #include <math.h>
25 #include "gsl_math.h"
26 #include "gsl_sf.h"
27 #include "gsl_sf_mathieu.h"
28
29
30 int gsl_sf_mathieu_Mc(int kind, int order, double qq, double zz,
31 gsl_sf_result *result)
32 {
33 int even_odd, kk, status;
34 double maxerr = 1e-14, amax, pi = M_PI, fn, factor;
35 double coeff[GSL_SF_MATHIEU_COEFF], fc;
36 double j1c, z2c, j1pc, z2pc;
37 double u1, u2;
38 gsl_sf_result aa;
39
40
41 /* Check for out of bounds parameters. */
42 if (qq <= 0.0)
43 {
44 GSL_ERROR("q must be greater than zero", GSL_EINVAL);
45 }
46 if (kind < 1 || kind > 2)
47 {
48 GSL_ERROR("kind must be 1 or 2", GSL_EINVAL);
49 }
50
51 amax = 0.0;
52 fn = 0.0;
53 u1 = sqrt(qq)*exp(-1.0*zz);
54 u2 = sqrt(qq)*exp(zz);
55
56 even_odd = 0;
57 if (order % 2 != 0)
58 even_odd = 1;
59
60 /* Compute the characteristic value. */
61 status = gsl_sf_mathieu_a(order, qq, &aa);
62 if (status != GSL_SUCCESS)
63 {
64 return status;
65 }
66
67 /* Compute the series coefficients. */
68 status = gsl_sf_mathieu_a_coeff(order, qq, aa.val, coeff);
69 if (status != GSL_SUCCESS)
70 {
71 return status;
72 }
73
74 if (even_odd == 0)
75 {
76 for (kk=0; kk<GSL_SF_MATHIEU_COEFF; kk++)
77 {
78 amax = GSL_MAX(amax, fabs(coeff[kk]));
79 if (fabs(coeff[kk])/amax < maxerr)
80 break;
81
82 j1c = gsl_sf_bessel_Jn(kk, u1);
83 if (kind == 1)
84 {
85 z2c = gsl_sf_bessel_Jn(kk, u2);
86 }
87 else /* kind = 2 */
88 {
89 z2c = gsl_sf_bessel_Yn(kk, u2);
90 }
91
92 fc = pow(-1.0, 0.5*order+kk)*coeff[kk];
93 fn += fc*j1c*z2c;
94 }
95
96 fn *= sqrt(pi/2.0)/coeff[0];
97 }
98 else
99 {
100 for (kk=0; kk<GSL_SF_MATHIEU_COEFF; kk++)
101 {
102 amax = GSL_MAX(amax, fabs(coeff[kk]));
103 if (fabs(coeff[kk])/amax < maxerr)
104 break;
105
106 j1c = gsl_sf_bessel_Jn(kk, u1);
107 j1pc = gsl_sf_bessel_Jn(kk+1, u1);
108 if (kind == 1)
109 {
110 z2c = gsl_sf_bessel_Jn(kk, u2);
111 z2pc = gsl_sf_bessel_Jn(kk+1, u2);
112 }
113 else /* kind = 2 */
114 {
115 z2c = gsl_sf_bessel_Yn(kk, u2);
116 z2pc = gsl_sf_bessel_Yn(kk+1, u2);
117 }
118 fc = pow(-1.0, 0.5*(order-1)+kk)*coeff[kk];
119 fn += fc*(j1c*z2pc + j1pc*z2c);
120 }
121
122 fn *= sqrt(pi/2.0)/coeff[0];
123 }
124
125 result->val = fn;
126 result->err = 2.0*GSL_DBL_EPSILON;
127 factor = fabs(fn);
128 if (factor > 1.0)
129 result->err *= factor;
130
131 return GSL_SUCCESS;
132 }
133
134
135 int gsl_sf_mathieu_Ms(int kind, int order, double qq, double zz,
136 gsl_sf_result *result)
137 {
138 int even_odd, kk, status;
139 double maxerr = 1e-14, amax, pi = M_PI, fn, factor;
140 double coeff[GSL_SF_MATHIEU_COEFF], fc;
141 double j1c, z2c, j1mc, z2mc, j1pc, z2pc;
142 double u1, u2;
143 gsl_sf_result aa;
144
145
146 /* Check for out of bounds parameters. */
147 if (qq <= 0.0)
148 {
149 GSL_ERROR("q must be greater than zero", GSL_EINVAL);
150 }
151 if (kind < 1 || kind > 2)
152 {
153 GSL_ERROR("kind must be 1 or 2", GSL_EINVAL);
154 }
155
156 amax = 0.0;
157 fn = 0.0;
158 u1 = sqrt(qq)*exp(-1.0*zz);
159 u2 = sqrt(qq)*exp(zz);
160
161 even_odd = 0;
162 if (order % 2 != 0)
163 even_odd = 1;
164
165 /* Compute the characteristic value. */
166 status = gsl_sf_mathieu_b(order, qq, &aa);
167 if (status != GSL_SUCCESS)
168 {
169 return status;
170 }
171
172 /* Compute the series coefficients. */
173 status = gsl_sf_mathieu_b_coeff(order, qq, aa.val, coeff);
174 if (status != GSL_SUCCESS)
175 {
176 return status;
177 }
178
179 if (even_odd == 0)
180 {
181 for (kk=0; kk<GSL_SF_MATHIEU_COEFF; kk++)
182 {
183 amax = GSL_MAX(amax, fabs(coeff[kk]));
184 if (fabs(coeff[kk])/amax < maxerr)
185 break;
186
187 j1mc = gsl_sf_bessel_Jn(kk, u1);
188 j1pc = gsl_sf_bessel_Jn(kk+2, u1);
189 if (kind == 1)
190 {
191 z2mc = gsl_sf_bessel_Jn(kk, u2);
192 z2pc = gsl_sf_bessel_Jn(kk+2, u2);
193 }
194 else /* kind = 2 */
195 {
196 z2mc = gsl_sf_bessel_Yn(kk, u2);
197 z2pc = gsl_sf_bessel_Yn(kk+2, u2);
198 }
199
200 fc = pow(-1.0, 0.5*order+kk+1)*coeff[kk];
201 fn += fc*(j1mc*z2pc - j1pc*z2mc);
202 }
203
204 fn *= sqrt(pi/2.0)/coeff[0];
205 }
206 else
207 {
208 for (kk=0; kk<GSL_SF_MATHIEU_COEFF; kk++)
209 {
210 amax = GSL_MAX(amax, fabs(coeff[kk]));
211 if (fabs(coeff[kk])/amax < maxerr)
212 break;
213
214 j1c = gsl_sf_bessel_Jn(kk, u1);
215 j1pc = gsl_sf_bessel_Jn(kk+1, u1);
216 if (kind == 1)
217 {
218 z2c = gsl_sf_bessel_Jn(kk, u2);
219 z2pc = gsl_sf_bessel_Jn(kk+1, u2);
220 }
221 else /* kind = 2 */
222 {
223 z2c = gsl_sf_bessel_Yn(kk, u2);
224 z2pc = gsl_sf_bessel_Yn(kk+1, u2);
225 }
226
227 fc = pow(-1.0, 0.5*(order-1)+kk)*coeff[kk];
228 fn += fc*(j1c*z2pc - j1pc*z2c);
229 }
230
231 fn *= sqrt(pi/2.0)/coeff[0];
232 }
233
234 result->val = fn;
235 result->err = 2.0*GSL_DBL_EPSILON;
236 factor = fabs(fn);
237 if (factor > 1.0)
238 result->err *= factor;
239
240 return GSL_SUCCESS;
241 }
242
243
244 int gsl_sf_mathieu_Mc_array(int kind, int nmin, int nmax, double qq,
245 double zz, gsl_sf_mathieu_workspace *work,
246 double result_array[])
247 {
248 int even_odd, order, ii, kk, status;
249 double maxerr = 1e-14, amax, pi = M_PI, fn;
250 double coeff[GSL_SF_MATHIEU_COEFF], fc;
251 double j1c, z2c, j1pc, z2pc;
252 double u1, u2;
253 double *aa = work->aa;
254
255
256 /* Initialize the result array to zeroes. */
257 for (ii=0; ii<nmax-nmin+1; ii++)
258 result_array[ii] = 0.0;
259
260 /* Check for out of bounds parameters. */
261 if (qq <= 0.0)
262 {
263 GSL_ERROR("q must be greater than zero", GSL_EINVAL);
264 }
265 if (kind < 1 || kind > 2)
266 {
267 GSL_ERROR("kind must be 1 or 2", GSL_EINVAL);
268 }
269
270 amax = 0.0;
271 fn = 0.0;
272 u1 = sqrt(qq)*exp(-1.0*zz);
273 u2 = sqrt(qq)*exp(zz);
274
275 /* Compute all eigenvalues up to nmax. */
276 gsl_sf_mathieu_a_array(0, nmax, qq, work, aa);
277
278 for (ii=0, order=nmin; order<=nmax; ii++, order++)
279 {
280 even_odd = 0;
281 if (order % 2 != 0)
282 even_odd = 1;
283
284 /* Compute the series coefficients. */
285 status = gsl_sf_mathieu_a_coeff(order, qq, aa[order], coeff);
286 if (status != GSL_SUCCESS)
287 {
288 return status;
289 }
290
291 if (even_odd == 0)
292 {
293 for (kk=0; kk<GSL_SF_MATHIEU_COEFF; kk++)
294 {
295 amax = GSL_MAX(amax, fabs(coeff[kk]));
296 if (fabs(coeff[kk])/amax < maxerr)
297 break;
298
299 j1c = gsl_sf_bessel_Jn(kk, u1);
300 if (kind == 1)
301 {
302 z2c = gsl_sf_bessel_Jn(kk, u2);
303 }
304 else /* kind = 2 */
305 {
306 z2c = gsl_sf_bessel_Yn(kk, u2);
307 }
308
309 fc = pow(-1.0, 0.5*order+kk)*coeff[kk];
310 fn += fc*j1c*z2c;
311 }
312
313 fn *= sqrt(pi/2.0)/coeff[0];
314 }
315 else
316 {
317 for (kk=0; kk<GSL_SF_MATHIEU_COEFF; kk++)
318 {
319 amax = GSL_MAX(amax, fabs(coeff[kk]));
320 if (fabs(coeff[kk])/amax < maxerr)
321 break;
322
323 j1c = gsl_sf_bessel_Jn(kk, u1);
324 j1pc = gsl_sf_bessel_Jn(kk+1, u1);
325 if (kind == 1)
326 {
327 z2c = gsl_sf_bessel_Jn(kk, u2);
328 z2pc = gsl_sf_bessel_Jn(kk+1, u2);
329 }
330 else /* kind = 2 */
331 {
332 z2c = gsl_sf_bessel_Yn(kk, u2);
333 z2pc = gsl_sf_bessel_Yn(kk+1, u2);
334 }
335 fc = pow(-1.0, 0.5*(order-1)+kk)*coeff[kk];
336 fn += fc*(j1c*z2pc + j1pc*z2c);
337 }
338
339 fn *= sqrt(pi/2.0)/coeff[0];
340 }
341
342 result_array[ii] = fn;
343 } /* order loop */
344
345 return GSL_SUCCESS;
346 }
347
348
349 int gsl_sf_mathieu_Ms_array(int kind, int nmin, int nmax, double qq,
350 double zz, gsl_sf_mathieu_workspace *work,
351 double result_array[])
352 {
353 int even_odd, order, ii, kk, status;
354 double maxerr = 1e-14, amax, pi = M_PI, fn;
355 double coeff[GSL_SF_MATHIEU_COEFF], fc;
356 double j1c, z2c, j1mc, z2mc, j1pc, z2pc;
357 double u1, u2;
358 double *bb = work->bb;
359
360
361 /* Initialize the result array to zeroes. */
362 for (ii=0; ii<nmax-nmin+1; ii++)
363 result_array[ii] = 0.0;
364
365 /* Check for out of bounds parameters. */
366 if (qq <= 0.0)
367 {
368 GSL_ERROR("q must be greater than zero", GSL_EINVAL);
369 }
370 if (kind < 1 || kind > 2)
371 {
372 GSL_ERROR("kind must be 1 or 2", GSL_EINVAL);
373 }
374
375 amax = 0.0;
376 fn = 0.0;
377 u1 = sqrt(qq)*exp(-1.0*zz);
378 u2 = sqrt(qq)*exp(zz);
379
380 /* Compute all eigenvalues up to nmax. */
381 gsl_sf_mathieu_b_array(0, nmax, qq, work, bb);
382
383 for (ii=0, order=nmin; order<=nmax; ii++, order++)
384 {
385 even_odd = 0;
386 if (order % 2 != 0)
387 even_odd = 1;
388
389 /* Compute the series coefficients. */
390 status = gsl_sf_mathieu_b_coeff(order, qq, bb[order], coeff);
391 if (status != GSL_SUCCESS)
392 {
393 return status;
394 }
395
396 if (even_odd == 0)
397 {
398 for (kk=0; kk<GSL_SF_MATHIEU_COEFF; kk++)
399 {
400 amax = GSL_MAX(amax, fabs(coeff[kk]));
401 if (fabs(coeff[kk])/amax < maxerr)
402 break;
403
404 j1mc = gsl_sf_bessel_Jn(kk, u1);
405 j1pc = gsl_sf_bessel_Jn(kk+2, u1);
406 if (kind == 1)
407 {
408 z2mc = gsl_sf_bessel_Jn(kk, u2);
409 z2pc = gsl_sf_bessel_Jn(kk+2, u2);
410 }
411 else /* kind = 2 */
412 {
413 z2mc = gsl_sf_bessel_Yn(kk, u2);
414 z2pc = gsl_sf_bessel_Yn(kk+2, u2);
415 }
416
417 fc = pow(-1.0, 0.5*order+kk+1)*coeff[kk];
418 fn += fc*(j1mc*z2pc - j1pc*z2mc);
419 }
420
421 fn *= sqrt(pi/2.0)/coeff[0];
422 }
423 else
424 {
425 for (kk=0; kk<GSL_SF_MATHIEU_COEFF; kk++)
426 {
427 amax = GSL_MAX(amax, fabs(coeff[kk]));
428 if (fabs(coeff[kk])/amax < maxerr)
429 break;
430
431 j1c = gsl_sf_bessel_Jn(kk, u1);
432 j1pc = gsl_sf_bessel_Jn(kk+1, u1);
433 if (kind == 1)
434 {
435 z2c = gsl_sf_bessel_Jn(kk, u2);
436 z2pc = gsl_sf_bessel_Jn(kk+1, u2);
437 }
438 else /* kind = 2 */
439 {
440 z2c = gsl_sf_bessel_Yn(kk, u2);
441 z2pc = gsl_sf_bessel_Yn(kk+1, u2);
442 }
443
444 fc = pow(-1.0, 0.5*(order-1)+kk)*coeff[kk];
445 fn += fc*(j1c*z2pc - j1pc*z2c);
446 }
447
448 fn *= sqrt(pi/2.0)/coeff[0];
449 }
450
451 result_array[ii] = fn;
452 } /* order loop */
453
454 return GSL_SUCCESS;
455 }