File: yn.c

package info (click to toggle)
python-scipy 0.18.1-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 75,464 kB
  • ctags: 79,406
  • sloc: python: 143,495; cpp: 89,357; fortran: 81,650; ansic: 79,778; makefile: 364; sh: 265
file content (107 lines) | stat: -rw-r--r-- 1,837 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/*                                                     yn.c
 *
 *     Bessel function of second kind of integer order
 *
 *
 *
 * SYNOPSIS:
 *
 * double x, y, yn();
 * int n;
 *
 * y = yn( n, x );
 *
 *
 *
 * DESCRIPTION:
 *
 * Returns Bessel function of order n, where n is a
 * (possibly negative) integer.
 *
 * The function is evaluated by forward recurrence on
 * n, starting with values computed by the routines
 * y0() and y1().
 *
 * If n = 0 or 1 the routine for y0 or y1 is called
 * directly.
 *
 *
 *
 * ACCURACY:
 *
 *
 *                      Absolute error, except relative
 *                      when y > 1:
 * arithmetic   domain     # trials      peak         rms
 *    IEEE      0, 30       30000       3.4e-15     4.3e-16
 *
 *
 * ERROR MESSAGES:
 *
 *   message         condition      value returned
 * yn singularity   x = 0              NPY_INFINITY
 * yn overflow                         NPY_INFINITY
 *
 * Spot checked against tables for x, n between 0 and 100.
 *
 */

/*
 * Cephes Math Library Release 2.8:  June, 2000
 * Copyright 1984, 1987, 2000 by Stephen L. Moshier
 */

#include "mconf.h"
extern double MAXLOG;

double yn(n, x)
int n;
double x;
{
    double an, anm1, anm2, r;
    int k, sign;

    if (n < 0) {
	n = -n;
	if ((n & 1) == 0)	/* -1**n */
	    sign = 1;
	else
	    sign = -1;
    }
    else
	sign = 1;


    if (n == 0)
	return (sign * y0(x));
    if (n == 1)
	return (sign * y1(x));

    /* test for overflow */
    if (x == 0.0) {
	mtherr("yn", SING);
	return -NPY_INFINITY * sign;
    }
    else if (x < 0.0) {
	mtherr("yn", DOMAIN);
	return NPY_NAN;
    }

    /* forward recurrence on n */

    anm2 = y0(x);
    anm1 = y1(x);
    k = 1;
    r = 2 * k;
    do {
	an = r * anm1 / x - anm2;
	anm2 = anm1;
	anm1 = an;
	r += 2.0;
	++k;
    }
    while (k < n);


    return (sign * an);
}