#include "chapter5.cpp"

typedef double runtype;
typedef std::vector<runtype> Array;
typedef std::vector<Array> Matrix;

inline runtype f(runtype x) {return (1.0/ exp(x * x)); }

ofstream outfile("chapter5.txt");

void main()
{
  int n = 1000;
  const runtype a = 0.0;
  const runtype b = 1.0;
  runtype sum_lower, sum_upper;

  sums(f, a, b, n, sum_lower, sum_upper);
  outfile << "Using Sums (with " << n << " runs)" << endl;
  outfile << "Lower sum = " << setw(15) << sum_lower << endl;
  outfile << "Upper sum = " << setw(15) << sum_upper << endl << endl;

  n = 60;
  runtype sum;

  trapezoid(f, a, b, n, sum);
  outfile << "Using Trapezoid Rule (with " << n << " runs)" <<endl;
  outfile << "Sum = " << setw(15) << sum << endl <<endl;

  n = 5;
  Matrix r(n+1, Array(n+1, 0.0));
  
  outfile << "Using Romberg Algorithm (with " << n*n << " runs)" << endl;
  romberg(outfile, f, a, b, n, r);
  outfile << endl;


  const runtype epsilon = 0.0000005; 
  int level = 0;
  int maxlevel = 20;
  runtype result;
  
  result = simpson(outfile, f, a, b, epsilon, level, maxlevel);
  outfile.precision(10);
  outfile << "Using Adaptive Simpson's (with " << maxlevel << " runs)" << endl; 
  outfile << "Approximate integral = " << setw(15) << result << endl;

}

