I am trying to write a program to find the integrals of a function, where the computer determines the number of slices that it should use, going through a loop until it finds the change small enought to ignore. I want it to have a tolerance of .01%
Can anyone whip up a bit of code?
This isn't for a class....personal useage. Im just blank on how to start it for the loop.
Edit: This is what I have for code thus far...but I think I don't have it set up right to include the loop that I need. Also, for N, I want to start at 25 and bump it up by 25 through each loop....
double myfunction(double) ;
double integrate(double lower, double upper, int N)
{
double width = (upper - lower) / N ;
double sum = 0.0 ;
double x ;
int i ;
for(i = 0 ; i < N ; i++ )
{
x = lower + width * (i + 0.5) ;
sum += width * myfunction(x) ;
}