# Numerical Methods Solution of nonlinear equations by using Bisection method in C

Numerical Methods: Solution of non-linear equations by using Bisection method in C

Algorithm:

1. Declare and initialize necessary variables like up_range, mid, low_range etc.
2. Read the range( upper and lower)  from user within which the root of the equation  is to be calculated.
3. If root lies within the range? if yes: go to step 4. if no: go to step 2
4. Calculate the mid value of upper and lower range, mid = (upper+lower)/2
5. Calculate the functional value at mid i.e. func(mid).
6. If func(mid)*func(low_range) is less than zero, then replace upper range by mid else replace lower range by mid
7. Display the no of iteration and root
8. if func(mid) is very small? yes: go to step 9. No: go to step 4
9. Display the value of most closest and accurate root.

Source Code:

```/********************************************
program: solution of non-linear equation
bisection method
language: C
Author : Bibek Subedi
Tribhuvan University, Nepal
************************************************/
#include
#include

//function that returns the functional value
float func(float x){
return (pow(x,3)+5*pow(x,2)-7);
}

int main(){
float up_range, low_range, mid;
int i = 0; //no of iteration
printf("Enter the range: ");
scanf("%f%f",&up_range,&low_range);
printf("\nThis range doesnot contains any root");
printf("\nEnter again the range: ");
scanf("%f%f",&up_range,&low_range);
}
do{
mid = (up_range + low_range) / 2;
if(func(low_range) * func(mid) < 0){ //if signs of mid and low_range is
up_range = mid;                  //different, replace up_range by mid
}else{ //else raplace, low_range by mid
low_range = mid;
}
i++;
printf("\nAt iteration: %d, root = %f",i,mid);
}while(fabs(func(mid))> 0.0001);

printf("\nThe root of the equation is %f", mid);
return 0;
}

Output: Related Posts July 29, 2012 Numerical Methods Solution of nonlinear equation using Newton Raphson method in C July 30, 2012 Numerical Methods Solution of nonlinear equation by using Secant method in C August 3, 2012 Numerical Methods Solution of simultaneous algebraic equations using Gauss Jordan method in C August 2, 2012 Numerical Methods Solution of simultaneous algebraic equations using Gauss Elimination method in C July 27, 2012 Numerical method  Solution of ordinary differential equation using RK4 method in CZemanta

```