Method of False Position
This method is an improvement over the bisection method. Like the bisection method, we start with an interval containing a solution. But instead of dividing the interval into two halves, we find the approximate solution by linear interpolation.
We call this method "false position method" because after each step an approximate(false) solution is calculated via linear interpolation. It is also called as Regula Falsi method. This method also requires the curve of function to be continuous inside the initial interval.
Method of False Position Graphical demonstration
Just like the bisection method, we start with two values and such that . After this, we find the next solution as the intersection between the x-axis and the line joining and whose equation will be:
Assigning and simplifying above, we get:
We will be using this formula of to find the next value of . In the bisection method, we calculated new but in this method we calculate new with .
Algorithm
The algorithm for bisection method can be written as:
- Start
- Read , , (Error threshold) and (Maximum number of iterations).
- Calculate and
- If , then doesn't bracket the solution, hence print the error and go to step 11.
- Declare , , and
- Calculate and
- If then assign , else assign .
- If and then goto step 9.
- Assign , and goto step 6.
- Print solution .
- Stop
Programs
- C
- Python
- Matlab
/**
* Method of False Position in C
*/
#include <stdio.h>
#include <math.h>
#define MAX_ITER 100
double f(double x)
{
return x * x - 2;
}
int main()
{
double x0, x1, threshold;
double x, x_prev=NAN, fx, fx0, fx1;
int iter = 0;
printf("---------Method of False Position---------\n");
printf("Enter x0: ");
scanf("%lf", &x0);
printf("Enter x1: ");
scanf("%lf", &x1);
fx1 = f(x1);
fx0 = f(x0);
// Check whether the interval brackets a solution
if (fx0 * fx1 >= 0)
{
printf("The given interval doesn't bracket a solution\n");
return -1;
}
printf("Enter error threshold: ");
scanf("%lf", &threshold);
printf("\nSolution:\n");
printf("%4s %10s %10s %10s %10s %10s %10s\n", "N", "x0", "x1", "f(x0)", "f(x1)", "x", "f(x)");
// Perform method of false position
while (iter < MAX_ITER)
{
x = x0 - (x1 - x0) * fx0 / (fx1 - fx0);
fx = f(x);
printf("%4d %10.5lf %10.5lf %10.5lf %10.5lf %10.5lf %10.5lf\n", iter + 1, x0, x1, fx0, fx1, x, fx);
// Reassign the interval
if (fx0 * fx < 0)
{
x1 = x;
fx1 = fx;
}
else
{
x0 = x;
fx0 = fx;
}
if (iter > 0 && fabs(x_prev - x) < threshold)
{
// Check for the error after at least one iteration is done
printf("\nHence, the solution is: %10.5lf\n", x);
return 0;
}
iter++;
x_prev = x;
}
printf("Max Iterations reached");
return -1;
}
#
# Method of False Position in Python
#
MAX_ITER = 100
def f(x):
return x*x - 2
def false_position(x0, x1, threshold):
x_prev = float('nan')
fx0 = f(x0)
fx1 = f(x1)
# Check whether the interval brackets a solution
if fx0*fx1 >= 0:
raise "The given interval doesn't bracket a solution"
iter = 0
print("\nSolution:")
print("%4s %10s %10s %10s %10s %10s %10s" %
("N", "x0", "x1", "f(x0)", "f(x1)", "x", "f(x)"))
while iter < MAX_ITER:
x = x0-(x1-x0)*fx0/(fx1-fx0)
fx = f(x)
print("%4d %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f" %
(iter, x0, x1, fx0, fx1, x, fx))
if fx0 * fx < 0:
x1, fx1 = x, fx
else:
x0, fx0 = x, fx
if iter > 0 and abs(x-x_prev) < threshold:
# Check for the error after at least one iteration is done
print("\nHence, the solution is: %10.5lf" % (x))
return
iter = iter+1
x_prev = x
raise "Max iterations reached"
print("---------Method of False Position---------")
x0 = float(input("Enter x0: "))
x1 = float(input("Enter x1: "))
threshold = float(input("Enter error threshold: "))
false_position(x0, x1, threshold)
%% Method of False Position in matlab/octave
MAX_ITER = 100;
% Declare the function
f = @(x) x*x-2;
printf('---------Method of False Position---------\n');
printf('Enter x0: ');
x0 = scanf('%f', 'C');
printf('Enter x1: ');
x1 = scanf('%f', 'C');
fx0 = f(x0);
fx1 = f(x1);
% Check whether the interval brackets a solution
if (fx0 * fx1 >= 0)
error('The given interval doesn''t bracket a solution\n');
endif
printf('Enter error threshold: ');
threshold = scanf('%f', 'C');
printf('\nSolution:\n');
printf('%4s %10s %10s %10s %10s %10s %10s\n', 'N', 'x0', 'x1', 'f(x0)', 'f(x1)', 'x', 'f(x)');
iter = 0;
x_prev = nan;
% Perform bisection method
while (iter < MAX_ITER)
x = x0-(x1-x0)*fx0/(fx1-fx0);
fx = f(x);
printf('%4d %10.5f %10.5f %10.5f %10.5f %10.5f %10.5f\n', iter + 1, x0, x1, fx0, fx1, x, fx);
% Reassign the interval
if (fx0 * fx < 0)
x1 = x;
fx1 = fx;
else
x0 = x;
fx0 = fx;
endif
if (iter > 0 && abs(x-x_prev)<threshold)
printf('\nHence, the solution is: %10.5f\n', x);
break;
endif
iter++;
x_prev = x;
endwhile
if (iter>=MAX_ITER)
error('Max iterations reached');
end
Output
---------Method of False Position---------
Enter x0: 1
Enter x1: 2
Enter error threshold: 0.001
Solution:
N x0 x1 f(x0) f(x1) x f(x)
1 1.00000 2.00000 -1.00000 2.00000 1.33333 -0.22222
2 1.33333 2.00000 -0.22222 2.00000 1.40000 -0.04000
3 1.40000 2.00000 -0.04000 2.00000 1.41176 -0.00692
4 1.41176 2.00000 -0.00692 2.00000 1.41379 -0.00119
5 1.41379 2.00000 -0.00119 2.00000 1.41414 -0.00020
Hence, the solution is: 1.41414
Convergence
In the regula falsi method, the error decreases by a factor after the iteration. The factor is variable for each iteration but the new error is always proportional to the previous error raised to power 1.
Thus, the rate of convergence is variable but the order of convergence is linear. The regula falsi method, on average, converges faster than the bisection method.
Advantages
- Higher rate of convergence than the bisection method
- Guaranteed convergence provided the initial conditions are met
Disadvantages
- More complex than the bisection method.
- Requires the solution to be bracketed.
- Order of convergence is linear despite the added complexity.