]>
Commit | Line | Data |
---|---|---|
1077fa4d EA |
1 | /* ynf.c |
2 | * | |
3 | * Bessel function of second kind of integer order | |
4 | * | |
5 | * | |
6 | * | |
7 | * SYNOPSIS: | |
8 | * | |
9 | * float x, y, ynf(); | |
10 | * int n; | |
11 | * | |
12 | * y = ynf( 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 function is evaluated by forward recurrence on | |
22 | * n, starting with values computed by the routines | |
23 | * y0() and y1(). | |
24 | * | |
25 | * If n = 0 or 1 the routine for y0 or y1 is called | |
26 | * directly. | |
27 | * | |
28 | * | |
29 | * | |
30 | * ACCURACY: | |
31 | * | |
32 | * | |
33 | * Absolute error, except relative when y > 1: | |
34 | * | |
35 | * arithmetic domain # trials peak rms | |
36 | * IEEE 0, 30 10000 2.3e-6 3.4e-7 | |
37 | * | |
38 | * | |
39 | * ERROR MESSAGES: | |
40 | * | |
41 | * message condition value returned | |
42 | * yn singularity x = 0 MAXNUMF | |
43 | * yn overflow MAXNUMF | |
44 | * | |
45 | * Spot checked against tables for x, n between 0 and 100. | |
46 | * | |
47 | */ | |
48 | \f | |
49 | /* | |
50 | Cephes Math Library Release 2.2: June, 1992 | |
51 | Copyright 1984, 1987, 1992 by Stephen L. Moshier | |
52 | Direct inquiries to 30 Frost Street, Cambridge, MA 02140 | |
53 | */ | |
54 | ||
55 | #include <math.h> | |
56 | extern float MAXNUMF, MAXLOGF; | |
57 | ||
58 | float y0f(float), y1f(float), logf(float); | |
59 | ||
60 | float ynf( int nn, float xx ) | |
61 | { | |
62 | float x, an, anm1, anm2, r, xinv; | |
63 | int k, n, sign; | |
64 | ||
65 | x = xx; | |
66 | n = nn; | |
67 | if( n < 0 ) | |
68 | { | |
69 | n = -n; | |
70 | if( (n & 1) == 0 ) /* -1**n */ | |
71 | sign = 1; | |
72 | else | |
73 | sign = -1; | |
74 | } | |
75 | else | |
76 | sign = 1; | |
77 | ||
78 | ||
79 | if( n == 0 ) | |
80 | return( sign * y0f(x) ); | |
81 | if( n == 1 ) | |
82 | return( sign * y1f(x) ); | |
83 | ||
84 | /* test for overflow */ | |
85 | if( x <= 0.0 ) | |
86 | { | |
87 | mtherr( "ynf", SING ); | |
88 | return( -MAXNUMF ); | |
89 | } | |
90 | if( (x < 1.0) || (n > 29) ) | |
91 | { | |
92 | an = (float )n; | |
93 | r = an * logf( an/x ); | |
94 | if( r > MAXLOGF ) | |
95 | { | |
96 | mtherr( "ynf", OVERFLOW ); | |
97 | return( -MAXNUMF ); | |
98 | } | |
99 | } | |
100 | ||
101 | /* forward recurrence on n */ | |
102 | ||
103 | anm2 = y0f(x); | |
104 | anm1 = y1f(x); | |
105 | k = 1; | |
106 | r = 2 * k; | |
107 | xinv = 1.0/x; | |
108 | do | |
109 | { | |
110 | an = r * anm1 * xinv - anm2; | |
111 | anm2 = anm1; | |
112 | anm1 = an; | |
113 | r += 2.0; | |
114 | ++k; | |
115 | } | |
116 | while( k < n ); | |
117 | ||
118 | ||
119 | return( sign * an ); | |
120 | } |