Binary method to find the realization code of the polynomial between 10 and 10 values

  • 2020-04-01 23:26:36
  • OfStack

The code is as follows:


#include <stdio.h>
#include <math.h>
int main()
{
 float  x0,x1,x2,f1,f2,f0;  //X1 and x2 are evaluated at both ends
 do
 {
  printf("input 2 num:n");
  scanf("%f %f",&x1,&x2);
  f1=x1*((2*x1-4)*x1+3)-6;
  f2=x2*((2*x2-4)*x2+3)-6;
 }while(f1*f2>0);  //The evaluation begins when the product of two inputs has an inconsistent sign
 do
 {
  x0=(x1+x2)/2;
  f0=x0 * ((2 * x0 -4) * x1 +3)-6;//X0 * (2 * x0 -4) * x1 +3)-6& PI; Polynomial of requirement
  if((f0*f1)<0)
  {
   x2=x0;
   f2=f0;
  }
  else
  {
   x1=x0;
   f1=f0;
  }
 }while(fabs(f0)>=1e-6);
 printf("x=%6.2fn",x0);
 return 0;
}


Related articles: