1 | /*************************************************************************
|
---|
2 | >>> SOURCE LICENSE >>>
|
---|
3 | This program is free software; you can redistribute it and/or modify
|
---|
4 | it under the terms of the GNU General Public License as published by
|
---|
5 | the Free Software Foundation (www.fsf.org); either version 2 of the
|
---|
6 | License, or (at your option) any later version.
|
---|
7 |
|
---|
8 | This program is distributed in the hope that it will be useful,
|
---|
9 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
11 | GNU General Public License for more details.
|
---|
12 |
|
---|
13 | A copy of the GNU General Public License is available at
|
---|
14 | http://www.fsf.org/licensing/licenses
|
---|
15 |
|
---|
16 | >>> END OF LICENSE >>>
|
---|
17 | *************************************************************************/
|
---|
18 |
|
---|
19 |
|
---|
20 | namespace alglib {
|
---|
21 | public class laguerre {
|
---|
22 | /*************************************************************************
|
---|
23 | Calculation of the value of the Laguerre polynomial.
|
---|
24 |
|
---|
25 | Parameters:
|
---|
26 | n - degree, n>=0
|
---|
27 | x - argument
|
---|
28 |
|
---|
29 | Result:
|
---|
30 | the value of the Laguerre polynomial Ln at x
|
---|
31 | *************************************************************************/
|
---|
32 | public static double laguerrecalculate(int n,
|
---|
33 | double x) {
|
---|
34 | double result = 0;
|
---|
35 | double a = 0;
|
---|
36 | double b = 0;
|
---|
37 | double i = 0;
|
---|
38 |
|
---|
39 | result = 1;
|
---|
40 | a = 1;
|
---|
41 | b = 1 - x;
|
---|
42 | if (n == 1) {
|
---|
43 | result = b;
|
---|
44 | }
|
---|
45 | i = 2;
|
---|
46 | while ((double)(i) <= (double)(n)) {
|
---|
47 | result = ((2 * i - 1 - x) * b - (i - 1) * a) / i;
|
---|
48 | a = b;
|
---|
49 | b = result;
|
---|
50 | i = i + 1;
|
---|
51 | }
|
---|
52 | return result;
|
---|
53 | }
|
---|
54 |
|
---|
55 |
|
---|
56 | /*************************************************************************
|
---|
57 | Summation of Laguerre polynomials using Clenshaws recurrence formula.
|
---|
58 |
|
---|
59 | This routine calculates c[0]*L0(x) + c[1]*L1(x) + ... + c[N]*LN(x)
|
---|
60 |
|
---|
61 | Parameters:
|
---|
62 | n - degree, n>=0
|
---|
63 | x - argument
|
---|
64 |
|
---|
65 | Result:
|
---|
66 | the value of the Laguerre polynomial at x
|
---|
67 | *************************************************************************/
|
---|
68 | public static double laguerresum(ref double[] c,
|
---|
69 | int n,
|
---|
70 | double x) {
|
---|
71 | double result = 0;
|
---|
72 | double b1 = 0;
|
---|
73 | double b2 = 0;
|
---|
74 | int i = 0;
|
---|
75 |
|
---|
76 | b1 = 0;
|
---|
77 | b2 = 0;
|
---|
78 | for (i = n; i >= 0; i--) {
|
---|
79 | result = (2 * i + 1 - x) * b1 / (i + 1) - (i + 1) * b2 / (i + 2) + c[i];
|
---|
80 | b2 = b1;
|
---|
81 | b1 = result;
|
---|
82 | }
|
---|
83 | return result;
|
---|
84 | }
|
---|
85 |
|
---|
86 |
|
---|
87 | /*************************************************************************
|
---|
88 | Representation of Ln as C[0] + C[1]*X + ... + C[N]*X^N
|
---|
89 |
|
---|
90 | Input parameters:
|
---|
91 | N - polynomial degree, n>=0
|
---|
92 |
|
---|
93 | Output parameters:
|
---|
94 | C - coefficients
|
---|
95 | *************************************************************************/
|
---|
96 | public static void laguerrecoefficients(int n,
|
---|
97 | ref double[] c) {
|
---|
98 | int i = 0;
|
---|
99 |
|
---|
100 | c = new double[n + 1];
|
---|
101 | c[0] = 1;
|
---|
102 | for (i = 0; i <= n - 1; i++) {
|
---|
103 | c[i + 1] = -(c[i] * (n - i) / (i + 1) / (i + 1));
|
---|
104 | }
|
---|
105 | }
|
---|
106 | }
|
---|
107 | }
|
---|