#include<stdio.h>#include<conio.h>#include<math.h>#define f(x) x*x*x-x-1int main(){float x0,x1,e,y0,y1,x2,y2;int i=0;printf("enter the initial guesses\n");scanf("%f%f",&x0,&x1);printf("enter the prescribed precision value\n");scanf("%f",&e);y0=f(x0);y1=f(x1);if(y0*y1>0){printf("initial guesses are not suitable\n");return(0);}//printline();printf("iter\tX0\tF(X0)\tX1\tF(X1)\tX2\tF(X2)\n");//printline();while (fabs((x1-x0)/x1)>=e){x2=(x0+x1)/2;y2=f(x2);i=i+1;printf(" %d\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\t%.2f\n",i,x0,y0,x1,y1,x2,y2);if(y0*y2>0){x0=x2;}else{x1=x2;}}printf("converges to the root\n");printf("number of iteration is %d\n",i);printf("root is %.2f",x2);getch();

}

## Wednesday, 23 April 2014

# Program to find the roots of a polynomial equation using bisection method

Subscribe to:
Post Comments (Atom)

## No comments:

Write comments