#include #include /* richard.c : 1999 3 2 by Y.Yamazaki and T.Oguni */ double diff(double (*f)(), double x, double h) { return ((*f)(x+h)-(*f)(x-h))/(2.0*h); } double richard(double (*f)(), double x, double h){ double a,b,c,d; a=f(x+h/2.0); b=f(x+h)/8.0; c=f(x-h/2.0); d=f(x-h)/8.0; return (a-b-c+d)/(h*(1.0-(1.0/4.0))); } double func(double x){ return x*sin(x); } double func1(double x){ return sin(x)+x*cos(x); } main(){ int i; double x, h=0.1; printf(" x\t f'(x)\t 通常\tリチャ−ドソン\n"); for (i=0, x=0.2; i<4; i++, x+=0.2){ printf("%.4f\t%.4f\t%.4f\t%.4f\n",x,func1(x),diff(func,x,h),richard(func,x,h)); } }