/* ATK IV - Numerical Programming (2006) */ /* Excercise 7.2 - Numerical Integration */ #include #include #define NRANSI #include int count = 0; float f(float x){ count+=1; return pow(x,4)*log(x+sqrt(x*x+1.0)); } int main(void){ float x1=0.0; float x2=2.0; float yt,ys,yr; int nt,ns,nr; yt=qtrap(f,x1,x2); nt=count; count=0; ys=qsimp(f,x1,x2); ns=count; count=0; yr=qromb(f,x1,x2); nr=count; printf("Trapezoidal: %f %d\n",yt,nt); printf("Simpson: %f %d\n",ys,ns); printf("Romberg: %f %d\n",yr,nr); printf("Exact: %f\n",8.15336411981116502054); return 0; }