Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/22/10 00:44:01 (14 years ago)
Author:
swagner
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.ALGLIB/2.5.0/ALGLIB-2.5.0/legendre.cs

    r3839 r4068  
    1717*************************************************************************/
    1818
    19 using System;
    2019
    21 namespace alglib
    22 {
    23     public class legendre
    24     {
    25         /*************************************************************************
    26         Calculation of the value of the Legendre polynomial Pn.
     20namespace alglib {
     21  public class legendre {
     22    /*************************************************************************
     23    Calculation of the value of the Legendre polynomial Pn.
    2724
    28         Parameters:
    29             n   -   degree, n>=0
    30             x   -   argument
     25    Parameters:
     26        n   -   degree, n>=0
     27        x   -   argument
    3128
    32         Result:
    33             the value of the Legendre polynomial Pn at x
    34         *************************************************************************/
    35         public static double legendrecalculate(int n,
    36             double x)
    37         {
    38             double result = 0;
    39             double a = 0;
    40             double b = 0;
    41             int i = 0;
     29    Result:
     30        the value of the Legendre polynomial Pn at x
     31    *************************************************************************/
     32    public static double legendrecalculate(int n,
     33        double x) {
     34      double result = 0;
     35      double a = 0;
     36      double b = 0;
     37      int i = 0;
    4238
    43             result = 1;
    44             a = 1;
    45             b = x;
    46             if( n==0 )
    47             {
    48                 result = a;
    49                 return result;
    50             }
    51             if( n==1 )
    52             {
    53                 result = b;
    54                 return result;
    55             }
    56             for(i=2; i<=n; i++)
    57             {
    58                 result = ((2*i-1)*x*b-(i-1)*a)/i;
    59                 a = b;
    60                 b = result;
    61             }
    62             return result;
    63         }
     39      result = 1;
     40      a = 1;
     41      b = x;
     42      if (n == 0) {
     43        result = a;
     44        return result;
     45      }
     46      if (n == 1) {
     47        result = b;
     48        return result;
     49      }
     50      for (i = 2; i <= n; i++) {
     51        result = ((2 * i - 1) * x * b - (i - 1) * a) / i;
     52        a = b;
     53        b = result;
     54      }
     55      return result;
     56    }
    6457
    6558
    66         /*************************************************************************
    67         Summation of Legendre polynomials using Clenshaw’s recurrence formula.
     59    /*************************************************************************
     60    Summation of Legendre polynomials using Clenshaw’s recurrence formula.
    6861
    69         This routine calculates
    70             c[0]*P0(x) + c[1]*P1(x) + ... + c[N]*PN(x)
     62    This routine calculates
     63        c[0]*P0(x) + c[1]*P1(x) + ... + c[N]*PN(x)
    7164
    72         Parameters:
    73             n   -   degree, n>=0
    74             x   -   argument
     65    Parameters:
     66        n   -   degree, n>=0
     67        x   -   argument
    7568
    76         Result:
    77             the value of the Legendre polynomial at x
    78         *************************************************************************/
    79         public static double legendresum(ref double[] c,
    80             int n,
    81             double x)
    82         {
    83             double result = 0;
    84             double b1 = 0;
    85             double b2 = 0;
    86             int i = 0;
     69    Result:
     70        the value of the Legendre polynomial at x
     71    *************************************************************************/
     72    public static double legendresum(ref double[] c,
     73        int n,
     74        double x) {
     75      double result = 0;
     76      double b1 = 0;
     77      double b2 = 0;
     78      int i = 0;
    8779
    88             b1 = 0;
    89             b2 = 0;
    90             for(i=n; i>=0; i--)
    91             {
    92                 result = (2*i+1)*x*b1/(i+1)-(i+1)*b2/(i+2)+c[i];
    93                 b2 = b1;
    94                 b1 = result;
    95             }
    96             return result;
    97         }
     80      b1 = 0;
     81      b2 = 0;
     82      for (i = n; i >= 0; i--) {
     83        result = (2 * i + 1) * x * b1 / (i + 1) - (i + 1) * b2 / (i + 2) + c[i];
     84        b2 = b1;
     85        b1 = result;
     86      }
     87      return result;
     88    }
    9889
    9990
    100         /*************************************************************************
    101         Representation of Pn as C[0] + C[1]*X + ... + C[N]*X^N
     91    /*************************************************************************
     92    Representation of Pn as C[0] + C[1]*X + ... + C[N]*X^N
    10293
    103         Input parameters:
    104             N   -   polynomial degree, n>=0
     94    Input parameters:
     95        N   -   polynomial degree, n>=0
    10596
    106         Output parameters:
    107             C   -   coefficients
    108         *************************************************************************/
    109         public static void legendrecoefficients(int n,
    110             ref double[] c)
    111         {
    112             int i = 0;
     97    Output parameters:
     98        C   -   coefficients
     99    *************************************************************************/
     100    public static void legendrecoefficients(int n,
     101        ref double[] c) {
     102      int i = 0;
    113103
    114             c = new double[n+1];
    115             for(i=0; i<=n; i++)
    116             {
    117                 c[i] = 0;
    118             }
    119             c[n] = 1;
    120             for(i=1; i<=n; i++)
    121             {
    122                 c[n] = c[n]*(n+i)/2/i;
    123             }
    124             for(i=0; i<=n/2-1; i++)
    125             {
    126                 c[n-2*(i+1)] = -(c[n-2*i]*(n-2*i)*(n-2*i-1)/2/(i+1)/(2*(n-i)-1));
    127             }
    128         }
     104      c = new double[n + 1];
     105      for (i = 0; i <= n; i++) {
     106        c[i] = 0;
     107      }
     108      c[n] = 1;
     109      for (i = 1; i <= n; i++) {
     110        c[n] = c[n] * (n + i) / 2 / i;
     111      }
     112      for (i = 0; i <= n / 2 - 1; i++) {
     113        c[n - 2 * (i + 1)] = -(c[n - 2 * i] * (n - 2 * i) * (n - 2 * i - 1) / 2 / (i + 1) / (2 * (n - i) - 1));
     114      }
    129115    }
     116  }
    130117}
Note: See TracChangeset for help on using the changeset viewer.