/* 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. */ printf(" Error in fakeInt. Got n = %d\n",n); 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=100; x=10; errorCode = fakeInt( &f, x, n); printf("got f= %12.4e, x=%12.4e, errorCode=%4d, n=%8d\n",f,x,errorCode,n); return 0; }