**Regula Falsi Method**, also known as the **false position method**, is an iterative method of finding the real roots of a function. This method works by substituting test values for unknown quantities, and is the oldest approach to solve equations in mathematics, numerical methods, and engineering. It is a closed bracket-type method with slow rate of convergence.

In earlier tutorials, we’d already gone through a C program and algorithm/flowchart for Regula Falsi method. Here, we’re going to write a program code for **Regula Falsi method in Matlab** along with its mathematical derivation and a numerical example.

False position method requires two initial guesses, and uses interpolation approach to find roots. Like the bisection method, the process starts with two guess values, say a and b such that f(a) and f(b) are of opposite sign which confirms that the root lies in the interval [a, b].

## Derivation of Regula Falsi Method:

Consider a curve having function f(x) = 0 as shown in the figure below:

It is required to locate the value of x at a point such that at that point the value of function is equal to zero i.e. x= r and f(r) = 0; ‘r’, which implies to the root of the equation f(x) = 0.

Consider three points on abscissa a_{1}, b_{1 }and c_{1 }with respective ordinates as f(a_{1}), f(b_{1}) and f(c_{1}). From the principle of similar triangle, we have:

[f(b_{1}) – f(a_{1})] /[ b_{1 }– _{ }a_{1}] = [ f(b_{1}) – 0 ] / [ b_{1} – c_{1}]

Rearranging the terms,

c_{1} = b_{1} – f(b_{1})/[ {f(b_{1}) – f(a_{1})}/{ b_{1}– _{ }a_{1 }}]

if f(c_{1}) = 0, the iteration is stopped, and c_{1 }= r. This is the required formula; the code for Regula Falsi method in MATLAB will be based on these formula and stopping criteria.

In real practice, it is very difficult and takes large number of iteration steps to exactly get f(r) = 0. That is why, we must initially define certain tolerance or allowed error in any program, whether it’s in MATLAB or C.

**Conditions for convergence of root:**

- When f(a
_{1}) and f(b_{1}) have opposite sign, the root lies in the interval [a_{1}, c_{1}]. In this case, the interval is shortened by b_{1}– c_{1}and b_{1}= c_{1}is set leaving a_{1}as it is. - If f(a
_{1}) and f(b_{1}) have same sign, the root lies in the interval [ c_{1}, b_{1}]. In this situation, interval is shortened by c_{1}– a_{1}and a_{1}= c_{1}is set leaving b_{1}as it is.

## Regula Falsi Method in MATLAB:

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 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
function a = regula_falsi( f ) %for Regula Falsi method % f is a function for which root to be found. % asking for the range f = @(x) x^3 -2*x - 5; R= input ( 'You are looking for the roots in [ x_min , x_max] :\n'); % check for range [ nr , mr ] = size( R); if nr ~= 1 || mr~= 2 disp( 'Input error ..The matrix should be 1x2 matrix') return end % if root lies in the boundary if feval( f , R( 1,1) )* feval( f , R(1,2)) == 0 if feval( f , R( 1,1) ) == 0 R(1,1) return else feval( f , R(1,2)) == 0 R(1,2) return end end % condition for convergence if feval( f , R( 1,1) )* feval( f , R(1,2)) > 0 disp ( 'Either NO root lies in the given range or EVEN no of roots') disp( 'lie in the given range and hence this method cannot be applied.'); return end %error allowed in final answer tol = abs(input(' Enter the error allowed in the final answer :')); % no of iterations to be performed n = input('Enter the maximum number of iterations to be performed :'); %initializing the value of k and matrix X k=1; X= zeros(n+1,3); %initial display of table & initializing values for look disp(sprintf('\t iterate \t value of x \t error')); x0= R(1,1); x1= R(1,2); x_disp= x0; err = x1-x0; disp(sprintf ('\t %3d \t %11.5f \t %11.5f ', 0, x_disp,err)); % iteration loop starts while k <=n && abs(err) > tol x = x1 - (x1-x0)/( feval(f,x1)-feval(f,x0) ) *feval(f,x1);%REGULA FALSI formula if feval(f , x0) * feval(f , x) == 0 x return else if feval(f,x0) * feval(f,x) <0 err = x - x1; x1 = x; x_disp=x1; X(k,2) = x1; else err = x-x0; x0 = x; x_disp = x0; X(k,2) = x0; end end % storing values in the form of matrix X(k,1) = k; X(k,3) = abs(err); disp(sprintf ('\t %3d \t %11.5f \t %11.5f ', k, x_disp,err)); k = k + 1; end if abs(err) > tol disp(sprintf ('The final answer obtained after %3d iterations is %10.10f with an error %10.10f \n' , n , X(n,2),X(n,3))) disp('Try more no of iterations for desired accuracy') else disp(sprintf ('The final answer obtained after %3d iterations is %10.10f with an error %10.10f \n' , (k-1) , X((k-1),2),X((k-1),3))) end m = menu('would you like to see how the process converges with iteration?',... 'show in graphical form','No thanks..Get me out of this'); switch m case 1 x=X(1:(k-1),1); y=X(1:(k-1),3); plot(x,y) xlabel (' No of iterations ') ylabel (' Error ') title ('Convergence of Regula-Falsi method') otherwise return end |

This program for **Regula Falsi method in MATLAB** finds the root of the function f(x) = x^{3} – 2x – 5 within the desired limit of accuracy as input by the user. The value of function can be modified and any function can be given as input.

When the program is executed, it asks for the values of initial guess interval, the allowed error and the maximum number of iterations to be performed. The program shows calculated results in each iteration in tabular form. Here’s a sample output of the program is given below:

## Regula Falsi Method Numerical Example:

Now, let’s analyze numerically the above program for Regula Falsi method in MATLAB. We have to determine the roots between (2,3) of equation x^{3} – 2x – 5 = 0, by using Regula Falsi method.

**Solution:**

Given equation: x^{3} – 2x – 5 = 0

Therefore, f(x) = x^{3} – 2x – 5.

Now, f(2) = 2^{3} – 2*2 – 5 = -1 and f(3) = 3^{3} – 2*3 – 5 = 16.

As f(2) and f (3) have opposite sign, it confirms that the root lies in the interval [2, 3].

Now, using the formula discussed in the derivation:

c_{1} = b_{1} – f(b_{1})/[ {f(b_{1}) – f(a_{1})}/{ b_{1}– a_{1 }}], where, a_{1} = 2 and b_{1} = 3

we get, c_{1 }= 2.058

f(c1) = f( 2.058) = -0.4.

So, the root lies in the interval [ 2.058, 3].

Again, using the formula:

c_{1} = b_{1} – f(b_{1})/[ {f(b_{1}) – f(a_{1})}/{ b_{1}– a_{1 }}], where, a1 = 2.058 and b1 = 3

we get, c_{1} = 2.081

f(c_{1} ) = f(2.081) = -0.15.

The process is repeated in similar manner until f(c_{1} ) comes under the desired degree of accuracy. The following tables shows the iteration procedure in this numerical example and the program of Regula Falsi method in MATLAB.

Thus, the approximate root of the given equation is 2.09, which is somewhat same as that obtained from the MATLAB program.

If you have any questions related to Regula Falsi method, its MATLAB code or mathematical derivation, bring them up from the comments section. You can find more Numerical Methods tutorial using MATLAB here.