Changeset 4068 for trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.ALGLIB/2.5.0/ALGLIB-2.5.0/laguerre.cs
- Timestamp:
- 07/22/10 00:44:01 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.ALGLIB/2.5.0/ALGLIB-2.5.0/laguerre.cs
r3839 r4068 17 17 *************************************************************************/ 18 18 19 using System;20 19 21 namespace alglib 22 { 23 public class laguerre 24 { 25 /************************************************************************* 26 Calculation of the value of the Laguerre polynomial. 20 namespace alglib { 21 public class laguerre { 22 /************************************************************************* 23 Calculation of the value of the Laguerre polynomial. 27 24 28 29 30 25 Parameters: 26 n - degree, n>=0 27 x - argument 31 28 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; 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; 42 38 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 } 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 } 60 54 61 55 62 63 56 /************************************************************************* 57 Summation of Laguerre polynomials using Clenshaws recurrence formula. 64 58 65 59 This routine calculates c[0]*L0(x) + c[1]*L1(x) + ... + c[N]*LN(x) 66 60 67 68 69 61 Parameters: 62 n - degree, n>=0 63 x - argument 70 64 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; 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; 82 75 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 } 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 } 93 85 94 86 95 96 87 /************************************************************************* 88 Representation of Ln as C[0] + C[1]*X + ... + C[N]*X^N 97 89 98 99 90 Input parameters: 91 N - polynomial degree, n>=0 100 92 101 Output parameters: 102 C - coefficients 103 *************************************************************************/ 104 public static void laguerrecoefficients(int n, 105 ref double[] c) 106 { 107 int i = 0; 93 Output parameters: 94 C - coefficients 95 *************************************************************************/ 96 public static void laguerrecoefficients(int n, 97 ref double[] c) { 98 int i = 0; 108 99 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 } 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 } 116 105 } 106 } 117 107 }
Note: See TracChangeset
for help on using the changeset viewer.