Bisection method is an iterative method used for the solution of non-linear equations, also known as binary chopping or half-interval method.
Bisection method is based on the repeated application of the intermediate value property. It means if f(x) is continuous in the interval [a, b] and f(a) and f(b) have different sign then the equation f(x) = 0 has at least one root between x = a and x = b.
This method is most reliable and simplest iterative method for solution of nonlinear equation.
a < x < b
where, x is not of nonlinear equation.
Let f(x) = 0 be continuous between ‘a’ and ‘b’. By definition let f(a) be negative and f(b) be positive. The first approximation to the root is
;
Where, a and b is selected such that,
Now, if f(x1) = 0 the x1 is the root of f(x) otherwise the root lies between ‘a’ and x1 or x1 and ‘b’ according as f(x1) is positive or negative. Then we bisect the interval as before and continue the process until the root is found to desired accuracy.
Algorithm of Bisection Method
Step 1: | Start |
Step 2: | Define function f(x) and error (E) |
Step 3: | Take two initial value for root as x1 and x2. |
Step 4: | Compute f(x1) and f(x2) |
Step 5: | If , then x1 and x2 do not coverage and root does not lies in between x1 and x2 and go to step (10); Otherwise continue. |
Step 6: | If f(x1) < 0 then set a = x1 and b = x2
Else, Set a = x2 and b = x1 |
Step 7: | Calculate root, and also calculate f(xn). |
Step 8: | If f(xn) > 0 (i.e. positive) then,
Set b =xn else, set a = xn |
Step 9: | Repeat till step (8), until absolute value of is less then E, then display root.
, go to step (10), ese to step (7). |
Step 10: | Stop |
Pseudocode of Bisection Method
Input f(x), e
Repeat
Input x1 and x2 till
Repeat
If assign x2 = 0
Else assign x1 = x0 till |x2 – x1| > e
Display root = x0
C Source Code of Bisection Method
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
#include <stdio.h> #include <math.h> #define f(x) pow(x,2) – 4*x-10 #define e 0.0001 Void main() { float x, x1, x2, x0; do { printf (“Enter the value of x1 and x2\n”); scanf(“%f %f”, &x1, &x2); } while (f(x1)*f(x2)>0); do { x0 = (x1 + x2)/2; if((f(x1)*f(x2))<0) { x2 = x0; } else x1 = x0; x = (x1 + x2)/2; }while (fabs(x0 - x)>e); printf(“root is =”, x0); getch(); } |
C++ Source code of bisection method
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
#include <iostream> #include <cmath> #define f(x) pow(x,2)-4*x-10 #define e 0.0001 using namespace std; int main() { float x, x2, x3, x0; do { cout<<”Enter the value of x1 and x2”<<endl; cin>>x1>>x2; } while(f(x1)*f(x2)>0); do { x0 = (x1 + x2)/2; if((f(x1)*f(x2))<0) { x2 = x0; } else x1 = x0; x = (x1 + x2)/2; }while(fabs(x0-x)>e); cout<<”Root is =”<<x0 <<endl; getch(); return 0; } |
Output: Enter the value of x1 and x2
1
-3
Root is = 0.999878
Check out other top popular Articles :
Clock Signal Generator Circuit