Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ParameterBinding/HeuristicLab.ExtLibs/HeuristicLab.ALGLIB/2.5.0/ALGLIB-2.5.0/laguerre.cs @ 12547

Last change on this file since 12547 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

File size: 3.1 KB
Line 
1/*************************************************************************
2>>> SOURCE LICENSE >>>
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License as published by
5the Free Software Foundation (www.fsf.org); either version 2 of the
6License, or (at your option) any later version.
7
8This program is distributed in the hope that it will be useful,
9but WITHOUT ANY WARRANTY; without even the implied warranty of
10MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11GNU General Public License for more details.
12
13A copy of the GNU General Public License is available at
14http://www.fsf.org/licensing/licenses
15
16>>> END OF LICENSE >>>
17*************************************************************************/
18
19
20namespace 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 Clenshaw’s 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}
Note: See TracBrowser for help on using the repository browser.