Good morning ;)
I'm currently improving my geometry code collection and searching for programming tasks involving numerical integration to test my code.
So far, I found the following:
- SGU 217 "Two Cylinders"
- ZOJ 2675 "Little Mammoth"
- UVa 12528 "Environment Protection" (thanks Hernan and mohammadrdeh)
- UVa 1280 "Curvy Little Bottles" (thanks Hernan)
- Timus 1562 "GM-pineapple" (thanks kolya37)
- SPOJ "CIRU" (thanks TobiichiOrigami)
I have to add that most of these can be solved explicitly as well :)
Do you know any similar tasks?
I'm using the following code (which I have not written myself!) which is a simple implementation of the adaptive Simpson's rule and which has served me quite well so far:
double simps(double a, double b) {
return (f(a) + 4*f((a+b)/2) + f(b))*(b-a)/6;
}
double integrate(double a, double b){
double m = (a+b)/2;
double l = simps(a,m), r = simps(m,b), tot=simps(a,b);
if (fabs(l+r-tot) < eps) return tot;
return integrate(a,m)+integrate(m,b);
}
I know two:
Also try this: http://www.spoj.com/problems/CIRU/
This problem may need this trick to reduce the call to f().
Thanks :) Yeah, the redundant calls to f() waste a lot of run time, but since typical tasks don't require a lot of optimization here, this is okay most of the times :) Nice to see that the optimized version is quite simple as well!
http://acm.timus.ru/problem.aspx?space=1&num=1562 But this problem is quite simpler than the ones you've shown and won't require Simpson's formula. ;)
"Latin America 2012 Problem E" can be useful.
I am so lucky to find this blog while i am solving SGU217. thank you!
Don't know if you're still looking for problems, but for future reference, CERC '07 Water is a good problem involving numeric integration (of general rational functions, too!).
Judging by the run times of currently accepted solutions, I don't think Little Mammoth is solved with numerical integration, instead I think it should be solved using Green's Theorem. Am I right?