/* stefatan.c -- Steffensen's method to solve tan(x) = x. Kincaid and Cheney Computer Exercise 3.2#9 An alternative approach with arctan. Written October 15, 2012 for Math 701 by Eric Olson */ #include #include int k; double f(double x){ return atan(x)-x+k*M_PI; } int main(){ printf( "Kincaid and Cheney Computer Exercise 3.2#9\n" "An alternative approach with arctan.\n" "Written October 15, 2012 for Math 701 by Eric Olson\n"); printf("\n%4s %24s\n","n","x"); for(k=0;k<=10;k++){ double x=1.0; int n; for(n=1;n<=10;n++){ double y=f(x); double d=f(x+y)-y; if(d==0.0 || y==0.0) break; x=x-y*y/d; } printf("%4d %24.15e\n",k,x); } return 0; }