using namespace std;
#include <iostream>
#include <assert.h>
#include <fstream>
#include<math.h>
#include "Resolution_analytique.h"


void startAnalytique(double pasX, double pasT, int DIMENSION){
    ofstream outfile ("analytique.dat");

    double grid [DIMENSION][DIMENSION];
    for(int i=0;i<DIMENSION;i++)
    {
        grid[i][0]=exp((0-0.5)*i*pasX)*i*pasX*(i*pasX-1);
    }
    for(int j=0;j<DIMENSION;j++)
    {
        grid[0][j]=0;
        grid[DIMENSION - 1][j]=0;
    }

    for(size_t i=0;i<DIMENSION-1;++i)
    {
        for(size_t j=0;j<=DIMENSION-1;++j)
        {
            grid[i][j]=0;
            double x = (double)i*pasX;
            double t = (double)j*pasT;
            for(int k=1; k<DIMENSION-1 ; ++k)
            {
                if ( i == 2 && j == 3 )
                {
                    cout << "Iteration n°" << k << " : " << grid[i][j] << endl;
                }
                grid[i][j]+=(pow((-1),(k))-1)/(pow((k*3.14),(3)))*exp(-(0.25+pow(k,(2))*9.86)*t)*exp(-(x/2))*sin(k*3.14*x);
                if ( i == 2 && j == 3 )
                {
                    cout << "\t variables  " << endl;
//                    cout << "\t\t numerateur   : " << numerateur << endl;
//                    cout << "\t\t denominateur : " << denominateur << endl;
//                    cout << "\t\t produit      : " << produit << endl;
                    cout << "\t\t exponentielle : " << exp(-(0.25+pow(k,(2))*9.86)*t) << endl;
                    cout << "\t\t calcul 1      : " << ( pow((-1),(k))-1)/(pow((k*3.14),(3)))*exp(-(0.25+pow(k,(2))*9.86)*t)*exp(-(x/2))*sin(k*3.14*x )  << endl;
                    cout << "\t\t value grid    : " << grid[i][j]  << endl;
                    cout << endl;
                }
            }
            outfile << x << "\t" << t << "\t" << 4*grid[i][j] << " \n";
            outfile << "\n";
        }
    }
    outfile.close();
    cout << "Resultat cree dans le fichier analytique.dat" << endl;
}

