Simpson's method for finding a the area under a curve, ie. The value of a definite integral for [a, b] is area = ((b-a)/6)*(f(a) + 4*f(m) + f(b)) where m is the midpoint of the interval.
I've already written a function S() that calculates this for a given interval and curve. I'm trying to write a new function AdaptiveSimpsons() which takes into account that some areas of the curve have more variations and thus require more subdivisions to get within a certain range of accuracy.
Pseudocode for this would be:
Subdivide interval [a, b] into two and check if those two parts are within desired uncertainty (there is a function already written for this)
If yes, add the interval to an array
If no, keep dividing until it satisfies, and add each subdivision to array
Run a loop that takes each interval from array and uses S() function to calculate area using Simpson's method.
I'm unsure of how to get the appropriate intervals without using recursion. I'm new to C so any help is appreciated.