2 template<double functionToIntegrate(double)>
3 double integrate(double a, double b, int numSamplePoints)
5 // PRECONDITION(numSamplePoints > 1);
6 double delta = (b-a) / (numSamplePoints-1);
8 for (int i=0; i < numSamplePoints; ++i)
9 sum += functionToIntegrate(a + i*delta);
10 return sum * (b-a) / numSamplePoints;
13 inline double myFunction(double x)
20 double z = integrate<myFunction>(0.0, 1.0, 50);