Working on a 1-d Harmonic oscillator using recursive functions, code works in fortran and trying to convert to C++ in order to learn the new syntax.
I have fixed all the notified errors so far searching through google, but still not getting a result. The program just runs seemingly forever without posting results.
I think the likely answer is maybe its not being calculated at all or there some some infinit loop because of a syntax problem in my for loop or called functions? but I am not seeing it and it is not identifying an error with them.
Any advice on why this program is not working properly?
//
//  main.cpp
//  1-d HO
//
//  Created by Grant Metheny on 3/2/16.
//  Copyright (c) 2016 Grant Metheny C++ Codes. All rights reserved.
//
#include <iostream>
#include <vector>
#include <string>
#include <fstream>
#include <cmath>
#include <math.h>
using namespace std;
int i = 0;
int n = 0;
double x = 1.;
double xmax = 5;
double imax = 1000;
double wavefunc = 0;
double fact = 1;
double hpol = 1;
double wf0 = 1;
double wf1 = 1;
double wf2 = 1;
double wf3 = 1;
double wf4 = 1;
double wf5 = 1;
double wf6 = 1;
double wavefunction(int n, double x)
{
    return wavefunc = pow(2.0,-(n*.5)) * pow(M_PI,.25) * exp(-(.5*pow(x,2.0)));
}
double factorial(int n)
{
    for (i = 0; i <= n; i++)
        
        if (i == 0)
             fact = 1.;
        else
             fact = fact * i;
    
    return fact;
}
double hermite(int n, double x)
{
    for (i = 0; i <= n; i++)
        if (i==1)
            hpol = 1.0;
        else if (n==1)
            hpol = 2*x;
        else
            hpol = 2*x*hermite(n-1,x) - 2*(n-1)*hermite(n-2,x);
    
    return hpol;
}
double dx = 2*xmax/imax;
int main(int argc, const char * argv[]) {
    
    
    for (i=0; i <= imax; i++) {
    
    x =  5. - dx*i;
    
    n = 0;
    wf0 = hermite(n,x) * wavefunction(n,x) * pow(factorial(n),(-(.5)));
    
    n = 1;
    wf1 = hermite(n,x) * wavefunction(n,x) * pow(factorial(n),(-(.5)));
    
    n = 2;
    wf2 = hermite(n,x) * wavefunction(n,x) * pow(factorial(n),(-(.5)));
    
    n = 3;
    wf3 = hermite(n,x) * wavefunction(n,x) * pow(factorial(n),(-(.5)));
    
    n = 4;
    wf4 = hermite(n,x) * wavefunction(n,x) * pow(factorial(n),(-(.5)));
    
    n = 5;
    wf5 = hermite(n,x) * wavefunction(n,x) * pow(factorial(n),(-(.5)));
    
    n = 6;
    wf6 = hermite(n,x) * wavefunction(n,x) * pow(factorial(n),(-(.5)));
    
    cout <<"I="<< i <<"X="<< x <<"WF0="<< wf0<<"WF1=" << wf1;  // wf2, wf3, wf4, wf5, wf6
    
}
    return 0;
} 
    