0% found this document useful (0 votes)
246 views

Program For Bisection Method

This document provides an overview of the bisection method for finding the real roots of a nonlinear function. It describes the key aspects of the bisection method, including that it is an iterative closed bracket method that requires two initial guesses. The document then provides the source code for a C program that implements the bisection method to find the root of the function x^3 - 4x - 9 between the initial guesses a and b. The program iterates until the difference between the guesses is less than the allowed error or the middle point is less than the allowed error.

Uploaded by

kaneki
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
246 views

Program For Bisection Method

This document provides an overview of the bisection method for finding the real roots of a nonlinear function. It describes the key aspects of the bisection method, including that it is an iterative closed bracket method that requires two initial guesses. The document then provides the source code for a C program that implements the bisection method to find the root of the function x^3 - 4x - 9 between the initial guesses a and b. The program iterates until the difference between the guesses is less than the allowed error or the middle point is less than the allowed error.

Uploaded by

kaneki
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 5

C Program for Bisection

Method
• Bisection method is an iterative implementation of the ‘Intermediate Value
Theorem‘ to find the real roots of a nonlinear function. According to the
theorem “If a function f(x)=0 is continuous in an interval (a,b), such that
f(a) and f(b) are of opposite nature or opposite signs, then there exists at
least one or an odd number of roots between a and b.”
• Using C program for bisection method is one of the simplest computer
programming approach to find the solution of nonlinear equations. It
requires two initial guesses and is a closed bracket method. Bisection
method never fails!
• The programming effort for Bisection Method in C language is simple and
easy. The convergence is linear, slow but steady. The overall accuracy
obtained is very good, so bisection method is more reliable in comparison
to the Newton Raphson method or the Regula-Falsi method.
• Features of Bisection Method:
• Type – closed bracket
• No. of initial guesses – 2
• Convergence – linear
• Rate of convergence – slow but steady
• Accuracy – good
• Programming effort – easy
• Approach – middle point
• Below is a source code in C program for bisection method to find a root of the nonlinear
function x^3 – 4*x – 9. The initial guesses taken are a and b. The calculation is done until
the following condition is satisfied:
• |a-b| < 0.0005 OR If (a+b)/2 < 0.0005 (or both equal to zero)
where, (a+b)/2 is the middle point value.
• Variables:
• itr – a counter variable which keeps track of the no. of iterations
performed
• maxmitr – maximum number of iterations to be performed
• x – the value of root at the nth iteration
• a, b – the limits within which the root lies
• allerr – allowed error
• x1 – the value of root at (n+1)th iteration
• f(x) = x^3 – 4*x – 9
do
#include<stdio.h> {
#include<math.h> if (fun(a)*fun(x) < 0)
float fun (float x) b=x;
{ else
return (x*x*x - 4*x - 9); a=x;
} bisection (&x1, a, b, &itr);
void bisection (float *x, float a, float b, int *itr) if (fabs(x1-x) < allerr)
{
// this function performs and prints the result of one iteration
{ printf("After %d iterations, root = %6.4f\n", itr, x1);
*x=(a+b)/2; return 0;
++(*itr); }
printf("Iteration no. %3d X = %7.5f\n", *itr, *x); x=x1;
} }
void main () while (itr < maxmitr);
{ printf("The solution does not converge or iterations are not
int itr = 0, maxmitr; sufficient");
float x, a, b, allerr, x1; return 1;
printf("\nEnter the values of a, b, allowed error and} maximum
iterations:\n");
scanf("%f %f %f %d", &a, &b, &allerr, &maxmitr);
bisection (&x, a, b, &itr);

You might also like