/* fdiff -- Compute approximation of derivatives Written September 6, 2012 for Math 701 by Eric Olson */ #include #include double x0=1.0; #include "f.h" double dq(double (*f)(double x),double x,double h){ return (f(x+h)-f(x))/h; } int main(){ double h; printf("fdiff -- Compute approximation of derivatives\n" "Written September 6 for Math 701 by Eric Olson\n"); printf("\nf(x)=%s\nf'(x)=%s\n\n",f_desc,df_desc); printf("%24s %24s %24s\n", "h","(f(x+h)-f(x))/h","error"); for(h=1e-3;h>1e-12;h/=2) printf("%24.16e %24.16e %24.16e\n", h,dq(f,x0,h),fabs(dq(f,x0,h)-df(x0))); }