/*    ATK IV - Numerical Programming (2006)      */
/*      Excercise 6.2 -  Brent's Method          */

#include<stdio.h>
#include<math.h>
#define NRANSI
#include<nr.h>
#define Pip4 0.785398163
#define nbmax 20

float f(float x){return cos(x-Pip4)+sin(x-Pip4/4)/(8.0*x);}

int main(void){

  float xacc=1.0e-6;
  float x1=1.0;
  float x2=20.0;
  int i,nb=nbmax;
  float xb1[nbmax+1],xb2[nbmax+1];
  float x;

  zbrak(f,x1,x2,nbmax,xb1,xb2,&nb);

  for(i=1;i<=nb;i++){
    x = zbrent(f,xb1[i],xb2[i],xacc);
    printf("%d %f\n",i,x);
  }

  return 0;
}