www.pudn.com > c.rar > FBNT.C, change:1980-01-01,size:996b


/**********************牛顿迭代法****************************/ 
/***x(0)存放迭代初值x0;x(1)返回实根值;eps为精度要求        */ 
#include "stdio.h" 
#include "math.h" 
int fbnt(x,eps,js) 
int js; 
double x[2],eps; 
{extern void fbntf(); 
int k,l; 
double y[2],d,p,x0; 
l=js;k=1;x0=x[0]; 
fbntf(x0,y); 
d=eps+1.0; 
while ((d>=eps)&&(l!=0)) 
{if(fabs(y[1])+1.0==1.0) 
  {printf("err\n");return(-1);} 
  x[1]=x0-y[0]/y[1]; 
  fbntf(x[1],y); 
  d=fabs(x[1]-x0);p=fabs(y[0]); 
  if(p>d)d=p; 
  x0=x[1];l=l-1; 
  } 
  k=js-l; 
  return(k); 
  } 
/************************************************************/ 
void fbntf(x,y) 
double x,y[2]; 
{y[0]=8820.0*x*x*x*x*x-2.31*x-431.0*0.015; 
y[1]=5.0*8820.0*x*x*x*x-2.31; 
return; 
} 
/************************************************************/ 
main() 
{int js,k; 
double x[2],eps; 
eps=0.0001;js=160;x[0]=1; 
k=fbnt(x,eps,js); 
if(k>=0) 
  printf("k=%d x=%e\n",k,x[1]); 
printf("\n"); 
} 
/**********************************************************/