// A procedure to be used for testing a Richardson based error estimator. // Just return a value corrupted with some errors proportional to various // powers of n. #include int fakeInt( double *f, double x, int n) { if ( n <= 0 ) { // Check for correctness of the input. cout << " Error in fakeInt. Got n = " << n << endl; return 1;} // Print an error message and quit with an error flag. *f = (double) 1.234 + x/(n*n) + ((double) 1 )/ (n*n*n) + (x*x)/(n*n*n*n); // This part adds errors designed to make the error estimator fail. // Comment it out if you want the error estimator to succeed. *f += n % 23; // Adding the residual of n mod 23 should give a function // that varies in a seemingly random way as n is decreased, // thus foiling the Richardson estimator. return 0; } /* A driver to check fakeInt. Comment out the whole thing before using. */ int main() { int n; double x; double f; int errorCode; n=1000; x=10; errorCode = fakeInt( &f, x, n); cout << "got f= "<< f << ", x= " << x << ", errorCode= " << errorCode ; cout << ", x = " << x << endl; return 0; }