Can someone help me

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <iomanip>
using namespace std;

double H( unsigned n, double x )       // "Physicist's" Hermite polynomial
{
   if ( n == 0 ) return 1;
   if ( n == 1 ) return 2 * x;
   return 2 * x * H( n - 1, x ) - 2 * ( n - 1 ) * H( n - 2, x );
}

double He( unsigned n, double x )      // "Probabilist's" Hermite polynomial
{
   if ( n == 0 ) return 1;
   if ( n == 1 ) return x;
   return x * He( n - 1, x ) - ( n - 1 ) * He( n - 2, x );
}

//==========================================================

int main()
{
   const int n = 4;               // e.g.

   #define SW << setw( 12 ) <<
   cout SW "x" SW "H(x)" SW "He(x)" << '\n';
   for ( int i = 0; i <= 10; i++ )
   {
      double x = i;
      cout SW x SW H( n, x ) SW He( n, x ) << '\n';
   }
}

C++ has std::hermite now, too: https://en.cppreference.com/w/cpp/numeric/special_math/hermite
(not an "recursive function" but perhaps a way to check yourself)
Last edited on
Thank-you @Cubbi!

I was having to type the polynomials out laboriously from the Wikipedia pages to check a few before posting.
Last edited on
Topic archived. No new replies allowed.