Paste: solving exponential
Author: | RrrrrrrrrOUGH I mean Rex |
Mode: | c++ |
Date: | Thu, 24 Apr 2014 03:25:06 |
Plain Text |
/*
Written by Reginald Ford
Computes the integral from 0 to endPt
of exp(t), which is exp(t).
Serves as a template for writing solvers
*/
#include <iostream>
#include <cmath>
#include <stdlib.h>
#include "pstools.h"
using namespace std;
#define MAXORDER 170
#define NUMEQS 1
//c[NUMEQS][order+1]
double c[1][MAXORDER];
void step(double stepSize, int order)
{
//build the coefficients
for(int i=0;i<=order;i++)
{
double oip1 = 1.0/(i+1.0);//over i+1
c[0][i+1] = oip1*c[0][i];
}
//evaluate the polynomials, and set new initial conditions
for(int i=0;i<NUMEQS;i++)
c[i][0]=polyval(c[i],stepSize,order);
//record your initial conditions
cout<<c[0][0]<<endl;
}
int main(int numArgs,char **argv)
{
int order = 0;
double endPt,stepSize;
if(numArgs != 4)
{
cout<<"Provide arguments:\n";
cout<<argv[0]<<" (order) (inverse stepSize) (endPt) \n";
return 0;
}
else
{
order = atoi(argv[1]);
stepSize = 1.0/atoi(argv[2]);
endPt = atoi(argv[3]);
if(order>MAXORDER)
cout<<"Order is above MAXORDER: "<<MAXORDER;
cout<<"order: "<<order<<" stepsize: "<<stepSize<<endl;
}
//initial conditions (t=0)
c[0][0] = 1;
//stepping. make sure that endPt is a multiple of stepSize
if(endPt < 0)
stepSize*=-1.0;
int numSteps = abs(endPt/stepSize);
for(int s=1;s<=numSteps;s++)
{
step(stepSize, order);
}
if(numSteps*stepSize < endPt)
step(endPt - numSteps*stepSize,order);
return 0;
}
New Annotation