Let us learn how to find the root of an interval using regula falsi method in C programming language.

Let us first understand what is a false position method and then let us see the C program for it.

#### What is False Position Method?

This method is also commonly known as **False Position Method**. It is basically a root finding method and is one of the oldest approaches. It is quite similar to **bisection method algorithm**.

Similar to the bisection method, the false position method also requires two initial guesses which are of opposite nature.

The false position method is also commonly known as **The Chords Method**. This method is an improvement over the slow convergence of bisection method.

The false position method is used to find the real roots of an equation using bracketing approach. This algorithm is used to solve transcendental equations.

Consider this non-linear function:

**f(x) = x ^{3} – 5**

where [ a = 1, b = 2 ] and Error = 0.001

#### Regula Falsi Method Theorem

Given a function **f(x)** on floating number **x** and two numbers **a** and **b** such that **f(a)*f(b) < 0** and **f(x)** is continuous in **[a, b]**.

The false position method algorithm or the Illinois Algorithm in C programming is used for finding roots which retain the prior estimates for which the function value has opposite sign from the function value at the current best estimate of the root.

#### Regula Falsi Method Algorithm

- Input an interval(start and end values), continuous function and function values f(a) and f(b).
- Find the mid-point (
**c**) value of the function. - If the transformation is satisfactory, return the mid-point and then stop the iteration.
- Check the sign value of f(c) and replace the appropriate function and values.

In another way, the algorithm of false position algorithm can also be represented in the following way:

Given a function f (x) continuous on an interval [a,b] and f (a) * f (b) < 0

1 2 3 4 5 6 7 | Do c = (a*f(b) - b*f(a))/(f(b) - f(a)) if f(c)*f(a) < 0 then b = c else a = c while(none of the convergence criterion C1, C2 or C3 is satisfied) |

#### Method 1: Regula Falsi Method in C Programming using If Else

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 55 56 57 | #include <stdio.h> #include <stdlib.h> #define function(m) ((m * m * m) - 25) int main() { float start_point, end_point, error = 0, midpoint, temp, allowed_error; int count = 0; printf("Enter Interval Start Point:\t"); scanf("%f", &start_point); printf("Enter Interval End Point:\t"); scanf("%f", &end_point); printf("Enter Allowed Error:\t"); scanf("%d", &allowed_error); printf("\n"); if((function(start_point) * function(end_point)) > 0) { printf("Invalid Intervals\n"); exit(0); } else if(function(start_point) == 0 || function(end_point) == 0) { printf("Root:\t%f\n", function(start_point) == 0 ? start_point:end_point); exit(0); } printf("ID\tStart\t\tEnd\t\tMid-Point\tf(Mid-Point)\tError\n\n"); do { temp = midpoint; midpoint = (((start_point * function(end_point)) - (end_point * function(start_point))) / (function(end_point) - function(start_point))); printf("%d\t%f\t%f\t%f\t%f\t", count++, start_point, end_point, midpoint, function(midpoint)); if(function(midpoint) == 0) { break; } else if(function(start_point) * function(midpoint) < 0) { end_point = midpoint; } else { start_point = midpoint; } error = fabs(midpoint - temp); if(count == 1) { printf("\n"); } else { printf("%f\n", error); } }while(error > allowed_error); printf("\n\nRoot of the Equation:\t%f\n", midpoint); return 0; } |

#### Output

If you have any doubts about the implementation of Regula Falsi method in C programming, let us know about it in the comment section.