Professional Documents
Culture Documents
1 Algorithm:
We can find the approximate root of an algebraic equation by the following steps
i Consider a continuous function f (x) that contains a zero (f (x) = 0 for any value of x) in
the interval [a : b].
ii First calculate the value of f (x) at the right end point b, that is, compute f (b).
iii Then calculate the value of f (x) at the left end point a, that is, compute f (a).
iv Then determine the product f (a)f (b), and find whether it satisfy condition f (a)f (b) < 0.
(Geometrically, this means that if f (a)f (b) < 0, then the curve f (x) has to cross the
x−axis at some point in between the interval [a : b]).
vi Compute the value of f (x) at the midpoint, that is, compute f (x1 ).
vii If f (x1 ) = 0, then stop the iteration process. Then x1 is the exact root.
viii Confirm the accuracy criteria by b−a2 < ǫ, where ǫ is the arbitrary small number. [If half
of the length of the interval [a : b] is less than ǫ, then the point x1 is within ǫ on the
actual root, and so stop the iteration process. x1 is a sufficiently close approximation to
the actual root].
ix If f (b)f (x1 ) < 0, then set a = x1 , and if f (b)f (x1 ) > 0 then set b = x1 . This ensures
that the smaller interval still contains the actual root and continue the iteration.
If the accuracy ǫ is not achieved after the pre-specified maximum number of iterations
allowed, then print out a failure message.
2 Problems:
1. Solve x3 − 9x + 1 = 0 for the root between x = 2 and x = 4, by bisection method.
3. Using bisection method find the positive root of xex = 1, which lies between 0 and 1.
1
Y
f(b)
f(x)
a
O x1 b X
f(a)
√
4. Using bisection method find the root of 3x = 1 + sin x.
√
5. Using bisection method find the approximate root of cos x = x.
3 Solution:
Problem 1: f (x) = x3 − 9x + 1 = 0
Problem 2: f (x) = x3 − x − 1 = 0
We consider the initial values of x for which f (x) become of opposite in sign. We take a = 1
and b = 2.
Let the accuracy is ǫ = 0.01.
2
n a b f (a) f (b) f (a)f (b) x1 f (x1 ) Accuracy
( b−a
2 < ǫ?)
1 1.000 2.000 -1.000 5.000 -5.000 1.500 0.875 No
2 1.000 1.500 -1.000 0.875 -0.875 1.250 -0.296 No
3 1.25 1.500 -0.296 0.875 -0.259 1.375 0.224 No
4 1.250 1.375 -0.296 0.224 -0.066 1.312 -0.051 No
5 1.3125 1.375 -0.0515 0.224 -0.011 1.343 0.082 No
6 1.3125 1.3437 -0.0515 0.0826 -0.004 1.328 0.014 No
7 1.3125 1.3281 -0.0515 0.0145 -0.0007 1.3203 -0.0187 Yes
3
and b = 1.
Let the accuracy is ǫ = 0.001.
n a b f (a) f (b) f (a)f (b) x1 f (x1 ) Accuracy
( b−a
2 < ǫ?)
1 0.0000 1.0000 -1.0000 1.6430 -1.6430 0.5000 0.2837 No
2 0.0000 0.5000 -1.0000 0.2837 -0.2837 0.2500 -0.3669 No
3 0.2500 0.5000 -0.3669 0.2837 -0.1041 0.3750 -0.0439 No
4 0.3750 0.5000 -0.0439 0.2837 -0.0124 0.4375 0.1193 No
5 0.3750 0.4375 -0.0439 0.1193 -0.0052 0.4062 0.0376 No
6 0.3750 0.4062 -0.0439 0.0376 -0.0016 0.3906 -0.0032 No
7 0.3906 0.4062 -0.0032 0.0376 -0.0001 0.3984 0.0172 No
8 0.3906 0.3984 -0.0032 0.0172 -0.0001 0.3945 0.0070 No
9 0.3906 0.3945 -0.0032 0.0070 -0.0000 0.3926 0.0019 No
10 0.3906 0.3926 -0.0032 0.0019 -0.0000 0.3916 -0.0006 No
4
n a b f (a) f (b) f (a)f (b) x1 f (x1 ) Accuracy
( b−a
2 < ǫ?)
1 0.0000 1.0000 1.0000 -0.4597 -0.4597 0.5000 0.1705 No
2 0.5000 1.0000 0.1705 -0.4597 -0.0784 0.7500 -0.1343 No
3 0.5000 0.7500 0.1705 -0.1343 -0.0229 0.6250 0.0204 No
4 0.6250 0.7500 0.0204 -0.1343 -0.0027 0.6875 -0.0563 No
5 0.6250 0.6875 0.0204 -0.0563 -0.0011 0.6562 -0.0178 No
6 0.6250 0.6562 0.0204 -0.0178 -0.0004 0.6406 0.0013 No
7 0.6406 0.6562 0.0013 -0.0178 -0.0000 0.6484 -0.0082 No
8 0.6406 0.6484 0.0013 -0.0082 -0.0000 0.6445 -0.0034 No
9 0.6406 0.6445 0.0013 -0.0034 -0.0000 0.6426 -0.0011 No
10 0.6406 0.6426 0.0013 -0.0011 -0.0000 0.6416 0.0001 Yes
4 Numerical code:
#include<stdio.h>
#include<math.h>
//function defination
double func(double x)
{
return 3*x-sqrt(1+sin(x));
}
double e=0.001; //Defines the permissible error
double c;
void bisection(double a, double b)
5
{
if(func(a) * func(b) >= 0)
{
printf(“Incorrect a and b.”);
return;
}
while ((b − a) >= e)
{
c = (a+b)/2;
if (func(c) == 0.0)
{
printf(“Root = %lf\ n”,c);
break;
}
else if (func(c)*func(a) < 0)
{
printf(“a=%lf\tb=%lf\tRoot = %lf\tf(x)=%lf\n”,a,b,c,func(c));
b = c;
}
else{
printf(“a=%lf\tb=%lf\tRoot = %lf\tf(x)=%lf\n”,a,b,c,func(c));
a = c;
}
}
}
int main()
{
double a,b;
a=0;
b=1;
printf(”a = %lf\n”,a);
printf(”b = %lf\n”,b);
bisection(a,b);
printf(”\n”);
printf(”Accurate Root calculated is = %lf\n”,c);
return 0;
}
ii One can guarantee the convergence of the iteration in case of solution of the equation; so
it always produces a root.
6
6 Demerits of bisection method:
i The convergence of this method is slow as it is simply based on halving the interval.
iii It also cannot be applied in an interval where the function always takes values of the
same sign.
v If one of the initial guesses a or b is closer to the exact solution, it will take larger number
of iterations to reach the root.