Bisection Method in CThis section will discuss the bisection method in the C programming language. The bisection method is a simple and convergence method used to get the real roots of nonlinear equations. The Bisection method repeatedly bisects or separates the interval and selects a subinterval in which the root of the given equation is found. It means if a function f(x) is continuous in the closed interval [a, b] and the f(a) and f(b) are two real numbers of opposite signs that contain at least one real root of f(x) = 0, between a and b. This method is also known as the Bolzano or Half Interval or Binary search method. Bisection Method Algorithm:Following is the algorithm of the Bisection Method in C.
If (f1 * f2) > 0, it displays the initial guesses are wrong and transfer control to step 11.
Example 1: Program to find the root of the given equation using the Bisection method Let's consider an example to get the approximation root of an equation using the Bisection method and for loop in the C programming language. Output: Enter the first starting point: 5 Enter the second ending point: 9 Enter the maximum iteration to be allowed: 8 Input the no. of allowed error point: 0.02 Iteration 1: 7.000000 Iteration 1: 8.000000 Iteration 2: 8.500000 Iteration 3: 8.750000 Iteration 4: 8.875000 Iteration 5: 8.937500 Iteration 6: 8.968750 Iteration 7: 8.984375 The approximation root is: 8.984375 Example 2: Program to find the real root of the (x^{3} + 3x  5 = 0) equation using the Bisection method Let's consider an example to print the real roots using the Bisection method in the C programming language. Output: Display the real roots of the given equation using the Bisection method: X ^ 3 + 3 * x  5 = 0 Enter the first approximation of the root: 1 Enter the second approximation of the root: 5 Input the number of iteration you want to perform: 7 The root after 1 iterations is 3.000000 The root after 2 iterations is 2.000000. The root after 3 iterations is 1.500000. The root after 4 iterations is 1.250000. The root after 5 iterations is 1.125000. The root after 6 iterations is 1.187500. The root after 7 iterations is 1.156250. The approximation root is 1.156250 Example 3: Program to find the approximation root of the nonalgebraic function using the Bisection method Let's create a simple program to calculate the approximation root using the Bisection method and do while loop in C programming language. Output: Input the initial approximation for x: 1 Input the initial approximation for y: 3 Define the input accuracy: .002 Input the maximum number of iteration: 10 Iteration x y z f(z) x  y 1 1.000000 3.000000 2.000000 0.479759 2.000000 2 1.000000 2.000000 1.500000 1.015806 1.000000 3 1.500000 2.000000 1.750000 0.479383 0.500000 4 1.750000 2.000000 1.875000 0.058267 0.250000 5 1.875000 2.000000 1.937500 0.195362 0.125000 6 1.875000 1.937500 1.906250 0.064801 0.062500 7 1.875000 1.906250 1.890625 0.002343 0.031250 8 1.875000 1.890625 1.882812 0.028192 0.015625 9 1.882812 1.890625 1.886719 0.012982 0.007812 10 1.886719 1.890625 1.888672 0.005334 0.003906 The root of the given equation is: 1.888672 Advantages of the Bisection Method:
Disadvantages of the Bisection Method
Next Topicsnprintf() function in C
