Generate hermite polynomial coefficients

In summary, the conversation discussed a code that generates coefficients of hermite polynomials up to a given order using recursion. The code was not working correctly and the individual was seeking assistance in finding the issue. They made some edits and were able to fix the issue with the order of variables in the output. However, the recursion was still not working correctly and they planned to consult their professor for further assistance.
  • #1
khemist
248
0

Homework Statement



I need to generate coefficients of hermite polynomials up to order k. Recursion will be used.

Homework Equations



a[n+1][k] = 2a[n][k-1] - 2na[n-1][k]

The Attempt at a Solution



Its not pretty, but here is my code.

Code:
#include <iostream>
#include <iomanip>
#include <cmath>
#include <math.h>
using namespace std;

int k_order;
int NDMN;
int x=0,y=0;

int main()
{       
        
    cout << "How many polynomials would you like to generate?";
    cin >> NDMN;
    
    float NARY[2][NDMN];
    
    while(y < (NDMN - 1))
    {
            while(x !=2)
            {
                    NARY[x][y] = 0;
                    x++;
                    }
            y++;
            x=0;
            }
    y = 0;
            
    NARY[0][0] = 1;
    NARY[0][1] = 0;
    NARY[1][1] = 2;

    while(y < (NDMN - 1))
    {
            while(x < 2)
            {
                    NARY[x][y+1] = 2 * NARY[x-1][y] - 2 * y * NARY[x][y-1];
                    x++;
                    }
            y++;
            x = 0;
            } 
    y = 0;
    while(y < (NDMN - 1))
    {
            while(x !=2)
            {
                    cout << NARY[x][y] << " ";
                    x++;
                    }
                    cout<<endl;
                    x = 0;
                    y++;
                    }
    system("pause");
    return 0;
}
The cout keeps giving me numbers on the order of 10^-30. To be honest, I cannot even really figure out what should be done. We are using Computational Methods in Physics an Engineering by Samuel Wong. The program we are writing is Box 4-5 in chapter 4. Any hints or tips on where I should start going? Thanks!
 
Physics news on Phys.org
  • #2
NARY[x][y+1] = 2 * NARY[x-1][y] - 2 * y * NARY[x][y-1];
You initialize and assign elements in your NARY array with indices 0..upwards. But this line when executed with x=0 and y=0 calls upon elements NARY[-1][0] etc.
 
  • #3
NascentOxygen said:
You initialize and assign elements in your NARY array with indices 0..upwards. But this line when executed with x=0 and y=0 calls upon elements NARY[-1][0] etc.

Alright thanks for the heads up.

In the box in our text, it claims we should use arguments K_Order - order of the hermite polynomial, and NDMN - dimension of the array NARY. I was wondering if anyone knew what the difference in this number would be. NDMN should either be the size of the order or should just be 2, so I am a little confused on what they mean by the two variables. Thanks
 
  • #4
Alright so I think I am getting closer. I figured that the k_order is the amount of times the recursion must be done. So if I want order 3, I have to do the recursion for order one, than order 2, than order 3, and output the array after doing order 3. So far, my code has been altered to this:

Code:
#include <iostream>
#include <iomanip>
#include <cmath>
#include <math.h>
using namespace std;

int k_order;
int NDMN;
int x=0,y=0;

int main()
{       
        
    cout << "What order polynomial would you like to generate?";
    cin >> k_order;
    
    NDMN = k_order;
    
    int NARY[NDMN][2];
    
    while(y < (NDMN - 1)) // This puts zeros in the array
    {
            while(x !=2)
            {
                    NARY[y][x] = 0;
                    x++;
                    }
            y++;
            x=0;
            }
             
    NARY[0][0] = 1; // Initialize the first few coefficients
    NARY[0][1] = 0;
    NARY[1][1] = 2;
    
    int q = 0;
    
    while(q < k_order)
    {
            x = 0;
            y = 2;
            while(y < (NDMN - 1))
            {
                    while(x < 2)
                    {
                            NARY[y][x] = 2 * x * NARY[y-1][x] - 2 * (y-1) * NARY[y-2][x];
                            x++;
                            cout << NARY[2][0];
                            }
                    y++;
                    x = 0;
                    } 
            q++;
            }
            
    y = 0;
    x = 0;
    while(y < (NDMN))
    {
            while(x !=2)
            {
                    cout << NARY[x][y] << " ";
                    x++;
                    }
                    cout<<endl;
                    x = 0;
                    y++;
                    }
    system("pause");
    return 0;
}

However, it doesn't seem to give the right values. The slot NARY[2][0] should be -2 after the first recursion, but even when I put cout << NARY[2][0] inside the x while loop the command is not printed. However, my x is less than 2, so it should be printed...
 
  • #5
Well I guess it actually does print the value. I am finding that when I get to higher order, the array should read:
-2 0
4 2

but it actually reads
0 -2
2 4

I have a feeling it just requires a switch of variables, but I am a little unsure...

edit: I realized the variables I had in the output were incorrect. I switched them and it seems to fix it, though the recursion still isn't quite correct. I am going to print my code out and see if my professor has any ideas, but I am always listening to any ideas you guys have. Thanks!
 
Last edited:

What are hermite polynomials?

Hermite polynomials are a set of orthogonal polynomials that are used in mathematical analysis and physics. They are named after the mathematician Charles Hermite and are commonly denoted as Hn(x).

What is the purpose of generating hermite polynomial coefficients?

The coefficients of hermite polynomials are used to represent functions in terms of orthogonal basis functions. This allows for simplification and approximation of complex functions, making them easier to analyze and manipulate.

How are hermite polynomial coefficients generated?

The coefficients of hermite polynomials can be generated using various methods, such as the Gram-Schmidt process, the three-term recurrence relation, or the Rodrigues formula. Each method has its own advantages and disadvantages, and the choice of method depends on the specific application.

What is the significance of the order of hermite polynomial coefficients?

The order of hermite polynomial coefficients corresponds to the degree of the polynomial. The higher the order, the more complex the polynomial and the more accurately it can represent a given function. However, as the order increases, the number of coefficients also increases, making the calculations more computationally intensive.

Are there any practical applications of hermite polynomial coefficients?

Yes, hermite polynomial coefficients have many practical applications in fields such as physics, engineering, and signal processing. They are commonly used in the solution of differential equations, interpolation, and curve fitting. They are also used in the numerical solution of problems involving heat transfer and quantum mechanics.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
3
Views
749
  • Engineering and Comp Sci Homework Help
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
24
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
935
  • Engineering and Comp Sci Homework Help
Replies
10
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
8
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
13
Views
2K
  • Programming and Computer Science
Replies
5
Views
2K
Back
Top