Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.ALGLIB/2.3.0/ALGLIB-2.3.0/laguerre.cs @ 3021

Last change on this file since 3021 was 2806, checked in by gkronber, 15 years ago

Added plugin for new version of ALGLIB. #875 (Update ALGLIB sources)

File size: 3.5 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
19using System;
20
21namespace alglib
22{
23    public class laguerre
24    {
25        /*************************************************************************
26        Calculation of the value of the Laguerre polynomial.
27
28        Parameters:
29            n   -   degree, n>=0
30            x   -   argument
31
32        Result:
33            the value of the Laguerre polynomial Ln at x
34        *************************************************************************/
35        public static double laguerrecalculate(int n,
36            double x)
37        {
38            double result = 0;
39            double a = 0;
40            double b = 0;
41            double i = 0;
42
43            result = 1;
44            a = 1;
45            b = 1-x;
46            if( n==1 )
47            {
48                result = b;
49            }
50            i = 2;
51            while( (double)(i)<=(double)(n) )
52            {
53                result = ((2*i-1-x)*b-(i-1)*a)/i;
54                a = b;
55                b = result;
56                i = i+1;
57            }
58            return result;
59        }
60
61
62        /*************************************************************************
63        Summation of Laguerre polynomials using Clenshaw’s recurrence formula.
64
65        This routine calculates c[0]*L0(x) + c[1]*L1(x) + ... + c[N]*LN(x)
66
67        Parameters:
68            n   -   degree, n>=0
69            x   -   argument
70
71        Result:
72            the value of the Laguerre polynomial at x
73        *************************************************************************/
74        public static double laguerresum(ref double[] c,
75            int n,
76            double x)
77        {
78            double result = 0;
79            double b1 = 0;
80            double b2 = 0;
81            int i = 0;
82
83            b1 = 0;
84            b2 = 0;
85            for(i=n; i>=0; i--)
86            {
87                result = (2*i+1-x)*b1/(i+1)-(i+1)*b2/(i+2)+c[i];
88                b2 = b1;
89                b1 = result;
90            }
91            return result;
92        }
93
94
95        /*************************************************************************
96        Representation of Ln as C[0] + C[1]*X + ... + C[N]*X^N
97
98        Input parameters:
99            N   -   polynomial degree, n>=0
100
101        Output parameters:
102            C   -   coefficients
103        *************************************************************************/
104        public static void laguerrecoefficients(int n,
105            ref double[] c)
106        {
107            int i = 0;
108
109            c = new double[n+1];
110            c[0] = 1;
111            for(i=0; i<=n-1; i++)
112            {
113                c[i+1] = -(c[i]*(n-i)/(i+1)/(i+1));
114            }
115        }
116    }
117}
Note: See TracBrowser for help on using the repository browser.