Friday 25 January 2019



Bisection Method

Find a root of the equation x3 − 5x + 3=0, using the bisection method and develop the C program for it.


SOURCE CODE:




#include<stdio.h>
#include<conio.h>
#include<math.h>
float fun(float x)
{
        return(x*x*x-5*x+3);
}

void main()
{
float a,b,eps,x;
int i=0;
clrscr();
printf("\n Enter the Lower and Upper limit:");
scanf("%f%f",&a,&b);
printf("\n Enter the epsilon value:");
scanf("%f",&eps);
if((fun(a)*fun(b))>0)
printf("\n starting value is unsuitable");

else
while(fabs((b-a)/b)>eps)
{
x=(a+b)/2;
i++;
if((fun(x)*fun(a))>0)
a=x;
else
b=x;
}
printf("\n\t Soultion Converges to a root.\n");
printf("\n Number of intration:%d\n",i);
printf("%f\n\t",x);
getch();

}

OUTPUT:


No comments:

Post a Comment