/* =========================================================== * RectangleRule_Prec: Precision-driven Rect Rule * =========================================================== */ #include float RectangleRule_Prec(float f(float), float a, float b, float EPS) { /* ------------------------------ "Local" Variables ------------------------------ */ int N; float V1, V2; // Successive estimates extern float RectangleRule(float(float), float, float, int); N = 1; V1 = RectangleRule(f, a, b, N); cout << "Approximation = " << V1 << "\n"; N = 2*N; V2 = RectangleRule(f, a, b, N); cout << "Approximation = " << V2 << "\n"; while ( fabs((V2 - V1)) > EPS ) { V1 = V2; N = 2*N; V2 = RectangleRule(f, a, b, N); cout << "Approximation = " << V2 << " |V2-V1| = " << fabs((V2 - V1)) << "\n"; } return(V2); }