The convergce process in the bisection method is very slow. It depends only on the choice of end points of the interval [a,b]. The function f(x) does not have any role in finding the point c (which is just the mid-point of a and b). It is used only to decide the next smaller interval [a,c] or [c,b]. A better approximation to c can be obtained by taking the straight line L joining the points (a,f(a)) and (b,f(b)) intersecting the x-axis. To obtain the value of c we can equate the two expressions of the slope m of the line L.
Let's take an Equation :- x*x*x-17
#include<stdio.h>
struct iter
{
float x1;
float x0;
};
float f(float x)
{
float y;
y=x*x*x-17;
return y;
}
float f1(float x)
{
float y1;
y1=3*x*x;
return y1;
}
void main()
{
int n,i;
float a,b,x0,x1,x2,x3,x4,x5,x6;
printf("enter the intervals");
scanf("%f%f" ,&a,&b);
printf("\nEnter the number of iterations\n");
scanf("%d",&n);
if(f(a)*f(b)<0)
{
printf("root is possible between interval %f %f " ,a,b);
}
else
{
printf("root does not lie between %f %f \n" ,a,b);
exit(1);
}
if(fabs(f(a))<fabs(f(b)))
x0=f(a);
else
x0=f(b);
x0=a;
printf("xnot is %f \n " ,x0 );
struct iter k[1000];
k[0].x0=x0;
i=0;
while(n!=0)
{
k[i].x1=k[i].x0-(f(k[i].x0)/f1(k[i].x0));
printf("\n%f" ,k[i].x1);
k[i+1].x0= k[i].x1;
--n;
++i;
}
}