2018年12月23日 星期日

Hermite coefficients

Program to demonstrate Hermite coefficients  C Code 

/***************************************************
*   Program to demonstrate Hermite coefficients    *
* ------------------------------------------------ *
* Reference: BASIC Scientific Subroutines, Vol. II *
* By F.R. Ruckdeschel, BYTE/McGRAWW-HILL, 1981 [1].*
*                                                  *
*              C++ Version by J.-P. Moreau, Paris. *
*                       (www.jpmoreau.fr)          *
* ------------------------------------------------ *
* SAMPLE RUN:                                      *
*                                                  *
* Hermite polynomial coefficients for order 2      *
*                                                  *
*   A( 0) =        -2                              *
*   A( 1) =         0                              *
*   A( 2) =         4                              *
*                                                  *
* Hermite polynomial coefficients for order 3      *
*                                                  *
*   A( 0) =         0                              *
*   A( 1) =       -12                              *
*   A( 2) =         0                              *
*   A( 3) =         8                              *
*                                                  *
* Hermite polynomial coefficients for order 4      *
*                                                  *
*   A( 0) =        12                              *
*   A( 1) =         0                              *
*   A( 2) =       -48                              *
*   A( 3) =         0                              *
*   A( 4) =        16                              *
*                                                  *
* Hermite polynomial coefficients for order 5      *
*                                                  *
*   A( 0) =         0                              *
*   A( 1) =       120                              *
*   A( 2) =         0                              *
*   A( 3) =      -160                              *
*   A( 4) =         0                              *
*   A( 5) =        32                              *
*                                                  *
* Hermite polynomial coefficients for order 6      *
*                                                  *
*   A( 0) =      -120                              *
*   A( 1) =         0                              *
*   A( 2) =       720                              *
*   A( 3) =         0                              *
*   A( 4) =      -480                              *
*   A( 5) =         0                              *
*   A( 6) =        64                              *
*                                                  *
* Hermite polynomial coefficients for order 7      *
*                                                  *
*   A( 0) =         0                              *
*   A( 1) =     -1680                              *
*   A( 2) =         0                              *
*   A( 3) =      3360                              *
*   A( 4) =         0                              *
*   A( 5) =     -1344                              *
*   A( 6) =         0                              *
*   A( 7) =       128                              *
*                                                  *
* Hermite polynomial coefficients for order 8      *
*                                                  *
*   A( 0) =      1680                              *
*   A( 1) =         0                              *
*   A( 2) =    -13440                              *
*   A( 3) =         0                              *
*   A( 4) =     13440                              *
*   A( 5) =         0                              *
*   A( 6) =     -3584                              *
*   A( 7) =         0                              *
*   A( 8) =       256                              *
*                                                  *
* Hermite polynomial coefficients for order 9      *
*                                                  *
*   A( 0) =         0                              *
*   A( 1) =     30240                              *
*   A( 2) =         0                              *
*   A( 3) =    -80640                              *
*   A( 4) =         0                              *
*   A( 5) =     48384                              *
*   A( 6) =         0                              *
*   A( 7) =     -9216                              *
*   A( 8) =         0                              *
*   A( 9) =       512                              *
*                                                  *
* Hermite polynomial coefficients for order 10     *
*                                                  *
*   A( 0) =    -30240                              *
*   A( 1) =         0                              *
*   A( 2) =    302400                              *
*   A( 3) =         0                              *
*   A( 4) =   -403200                              *
*   A( 5) =         0                              *
*   A( 6) =    161280                              *
*   A( 7) =         0                              *
*   A( 8) =    -23040                              *
*   A( 9) =         0                              *
*   A(10) =      1024                              *
*                                                  *
****************************************************
 Explanations
 ------------

 Hermite polynomials are defined over the range -inf. < x < inf. The weight-
 ing function is w(x) = e^(-x^2):

    inf.
    Sum   e^(-x^2) H (x) H (x) dx = 0     for n <> m         (3.9.8)
    -inf.           n     m
                                  = f(n)  for n = m

 The corresponding recursion relation is

    H   (x) = 2x H (x) - 2n H   (x)                          (3.9.9)
     n+1          n          n-1

 where H (x) = 1  and  H (x) = 2x
        0               1

 As with the other polynomials, a simple subroutine for evaluating the coefficients
 be written (see program HERMITE).

 Note that Hermite polynomials are either even or odd, depending on N, and the co-
 efficients are integers.
---------------------------------------------------------------------------------- */
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
double  A[11];
double  B[11][11];
int     n,k;


/*************************************************
* Hermite polynomial coefficients evaluation by  *
* means of recursion relation. The order of the  *
* polynomial is n. The coefficients are returned *
* in A(i).                                       *
*************************************************/
void Hermite_Coeff()  {
  int i,j;
  //Establish l0 and l1 coefficients
  B[0][0]=1.0 ; B[1][0]=0.0 ; B[1][1]=2.0;
  //Return if order is less than two
  if (n>1)  {
    for (i=2; i<n+1; i++)  {
      B[i][0]=-2*(i-1)*B[i-2][0];
      for (j=1; j<i+1; j++)
        //Basic recursion relation
        B[i][j]=2*B[i-1][j-1]-2*(i-1)*B[i-2][j];
    }
    for (i=0; i<n+1; i++)  A[i]=B[n][i];
  }
}


int main(int argc, char *argv[])
{
  for (n=2; n<11; n++)  {
    printf("\n Hermite polynomial coefficients for order %d\n\n",n);

    Hermite_Coeff();

    for (k=0; k<n+1; k++)
  printf("   A(%2d) = %9.0f\n",k,A[k]);
    if (n<10) getchar();
  }
  printf("\n");
  return 0;
}


// End of file Hermite.cpp

沒有留言:

張貼留言

Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --3

  Node-Red Dashboard UI Template + AngularJS 參考 AngularJS教學 --3 AngularJS 實例 <!DOCTYPE html> <html> <head> <meta charse...