Lab 5: Regula-Falsi Method
Introduction:
In numerical analysis, Regula-Falsi Method (also called False Position Method) is one of an
iterative, closed bracketing and convergence guaranteed method for finding real root of non-
linear equations. This method works by substituting test values for unknown quantities, and is
the oldest approach to solve equations in mathematics, numerical methods, and engineering.
Objectives:
The objectives of this experiment are;
1. To determine roots of an equation in single variable using Regula Falsi method.
2. To understand the MATLAB implementation of the Regula Falsi method.
3. To analyze of results using different initial values.
Preliminary Work (to be done before lab session):
1. Consider the function (𝑥) = ln(x − 1) + cos(x − 1) = 0, find a root of the function using the
interval 1.3 ≤ x ≤ 2. Perform 10 iterations of the Regula Falsi method. Use the tolerance up to
5 decimal places.
2. Understand the algorithm, the corresponding pseudo-code and MATLAB code of the Regula
Falsi method.
Regula-Falsi Method (Theoretical Explanation):
Regula-Falsi method requires two initial guesses, and uses interpolation approach to find roots.
Like Bisection method, false position method also starts with the value of intervals [a, b] but we
cannot compute the mid-point from the interval but we draw a secant line which passes through
f(a) and f(b) and the point where this line intersect the x-axis is called c k which represents an
improved estimate of the root. The fact that the replacement of the curve by a straight line gives
the false position of the root is the origin of the name, method of false position, or in Latin,
Regula Falsi. It is also called the Linear Interpolation Method.
Regula Falsi Method is bracketing method which means it starts with two initial guesses say x0
and x1 such that x0 and x1 brackets the root i.e. f(x0)*f(x1) < 0. Regula Falsi is based on the fact
that if f(x) is real and continuous function, and for two initial guesses x0 and x1 brackets the root
such that: f(x0)*f(x1) < 0 then there exists at least one root between x0 and x1.
If x0 and x1 are two guesses, then we compute new approximated root as:
(x ¿ ¿ 0−x 1)∗f (x 0 )
x 2=x 0− ¿
f (x¿ ¿ 0)−f ( x 1 )¿
Now we have following three different cases:
a) If f(x2) = 0, then the root is x2.
b) If (x0)*f(x2) < 0 then root lies between x0 and x2.
c) If (x0)*f(x2) > 0 then root lies between x1 and x2.
Steps for executing the Regula-Falsi Method
1. Choose two initial points a and b such that f(a) and f(b) have opposite signs (f(a)*f(b) < 0)
2. Estimate the root (ck) by using the following expression
a k f ( bk ) −b k f ( ak )
ck= where k = 1, 2, 3, …..
f ( bk ) −f ( ak )
For Loop Condition: If k = 1, then a1 = a and b1 = b
3. Compute f(ck).
4. In this method, we will implement the following basic conditions for finding the region of
signs:
If f(a)*f(ck) < 0, set ak+1 = ak and bk+1 = ck, then root lies between a and c.
If f(b)*f(ck) < 0, set ak+1 = ck and bk+1 = bk, then root lies between b and c.
where ak+1 is next iteration value of a whereas ak is the previous iteration value of a. Similarly,
bk+1 is the next iteration value of b. But bk+1 and ak+1 values are updated with ck value.
5. Repeat step 2 until you start getting same values for ck up to 4 decimal places or find the root
within desired accuracy.
Experiment:
Software Required: MATLAB
Procedure:
1. Algorithm for Regula-Falsi Method (Step Wise)
Consider a curve having function f(x) = 0 as shown in the figure below:
Figure: Graphical description of the Regula Falsi Method.
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.
if f(ck) = 0, the iteration is stopped, and c k = r. This is the required formula; the code for Regula
Falsi method in MATLAB will be based on these formula and stopping criteria. For finding the
root of the function, the one of the following stopping criteria can be used.
|f(ck)| < tolerance (ε)
|f(ck - ck-1)| < tolerance (ε)
|f(ck - ck-1)|/ ck < tolerance (ε)
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.
1. start
2. Define function f(x)
3. Choose initial guesses a1 and b1 such that f(a)*f(b) < 0 (Root bracketing criteria)
4. Choose pre-specified tolerable error (e).
5. Choose No. of iterations (n)
6. Calculate new approximated root (ck) using k = 1 in the following formula:
a k f ( bk ) −b k f ( ak )
ck= where k = 1, 2, 3, …..
f ( bk ) −f ( ak )
7. Calculate f(a)*f(ck)
If f(a)*f(ck) < 0, set ak+1 = ak and bk+1 = ck, then root lies between a and c.
If f(b)*f(ck) < 0, set ak+1 = ck and bk+1 = bk, then root lies between b and c.
if f(a)*f(ak) = 0 then go to step 8.
8. if |f(ck)| > e then go to step 6 otherwise go to step 9
9. Display ck as root.
10. Stop
2. Pseudocode for Regula-Falsi Method
Pseudocode for Regula-Falsi method involves following steps in order to solve any non-linear
equation with the help of computational tools:
1. Start
2. Define function f(x)
3. Inputs
a. Lower and Upper guesses a and b
b. Tolerable error (e)
c. No. of Iterations (n)
4. If f(a)*f(b) > 0 && a<b
print "Incorrect initial guesses"
go to step 3
End
5. For i = 1:n
a k f ( bk ) −b k f ( ak )
ck=
f ( bk ) −f ( ak )
If abs(f(ck)) < e
Break
End
If f(a)*f(ck) < 0
b = ck
Elseif f(b)*f(c) < 0
a = ck
End
End
6. Print root as ck.
7. Stop
MATLAB Program 1:
Consider the function (𝑥) = ln(x − 1) + cos(x − 1) = 0, find a root of the function using the
interval 1.3 ≤ x ≤ 2. Perform 10 iterations of the Regula-Falsi method. Use tolerance up to 5
decimal places.
Code Implementation:
% Define the function
f = @(x) log(x-1) + cos(x-1);
% Define the interval [a,b], iterations and tolerance level
a = 1.3;
b = 2;
n = 10;
e = 1e-5;
% Processing
if f(a)*f(b) < 0 && a < b
for i=1:n
c = (a*f(b)-b*f(a))/(f(b)-f(a));
fprintf('P%d = %.5f\n',i,c)
if abs(f(c))<e
break
end
if f(a)*f(c) < 0
b = c;
elseif f(b)*f(c) < 0
a = c;
end
end
else
disp('No root between given brackets')
end
% Print the root
fprintf('The root is approximately %.5f\n', c)
Code Output:
P1 = 1.52061
P2 = 1.41837
P3 = 1.40114
P4 = 1.39830
P5 = 1.39784
P6 = 1.39776
P7 = 1.39775
Question:
1. How does the choice of the initial interval affect the solution?
MATLAB Program 2:
Consider the function 𝑓(𝑥) = ex -2 - x = 0, start with interval [a0, b0] = [-2.4, -1.6]. Use the
Regula-Falsi method to compute c0, c1, c2, c3. Perform 5 iterations of the Regula-Falsi method.
Use tolerance up to 5 decimal places.
Code Implementation:
% Define the function
f = @(x) exp(x) - 2 - x;
% Define the interval [a0,b0], iterations and tolerance
level
a0 = -2.4;
b0 = -1.6;
n = 5;
e = 1e-5;
% Processing
if f(a0)*f(b0) < 0 && a0 < b0
for i=0:n
c0 = (a0*f(b0)-b0*f(a0))/(f(b0)-f(a0));
fprintf('C%d = %.5f\n',i,c0)
if abs(f(c0))<e
break
end
if f(a0)*f(c0) < 0
b0 = c0;
elseif f(b0)*f(c0) < 0
a0 = c0;
end
end
else
disp('No root between given brackets')
end
% Print the root
fprintf('The root is approximately %.5f\n', c0)
Code Output:
C0 = -1.83008
C1 = -1.84093
C2 = -1.84139
C3 = -1.84140
The root is approximately -1.84140
Generalized Code Format for Regula-Falsi Method:
Program 1:
% Ingredients
f = input ('Enter your function = ');
a = input ('Enter left side of your Root guess = ');
b = input ('Enter right side of your Root guess = ');
n = input ('Enter no of iterations = ');
e = input ('Enter tolerance = ');
% Processing
if f(a)*f(b) < 0 && a < b
for i=1:n
c = (a*f(b)-b*f(a))/(f(b)-f(a));
fprintf('P%d = %.5f\n',i,c)
if abs(f(c))<e
break
end
if f(a)*f(c) < 0
b = c;
elseif f(b)*f(c) < 0
a = c;
end
end
else
disp('No root between given brackets')
end
% Print the root
fprintf('The root is approximately %.5f\n', c)
Program 2:
% Ingredients
f = input ('Enter your function = ');
a0 = input ('Enter left side of your Root guess = ');
b0 = input ('Enter right side of your Root guess = ');
n = input ('Enter no of iterations = ');
e = input ('Enter tolerance = ');
% Processing
if f(a0)*f(b0) < 0 && a0 < b0
for i=0:n
c0 = (a0*f(b0)-b0*f(a0))/(f(b0)-f(a0));
fprintf('C%d = %.5f\n',i,c0)
if abs(f(c0))<e
break
end
if f(a0)*f(c0) < 0
b0 = c0;
elseif f(b0)*f(c0) < 0
a0 = c0;
end
end
else
disp('No root between given brackets')
end
% Print the root
fprintf('The root is approximately %.5f\n', c0)
1st Function Output:
Enter your function = @(x) log(x-1) + cos(x-1)
Enter left side of your Root guesss = 1.3
Enter right side of your Root guesss = 2
Enter no of iterations = 10
Enter tolerance = 1e-5
P1 = 1.52061
P2 = 1.41837
P3 = 1.40114
P4 = 1.39830
P5 = 1.39784
P6 = 1.39776
P7 = 1.39775
The root is approximately 1.39775
2nd Function Output:
Enter your function = @(x) exp(x) - 2 - x
Enter left side of your Root guess = -2.4
Enter right side of your Root guess = -1.6
Enter no of iterations = 5
Enter tolerance = 1e-5
C0 = -1.83008
C1 = -1.84093
C2 = -1.84139
C3 = -1.84140
The root is approximately -1.84140
Lab Report Template (Psychomotor Domain)
Title/Cover Page
The title page of your Lab report should include the following information:
a) NUTECH Logo
b) No. and Name of the Experiment
c) Submitted To: Name of Instructor - Dr. Muhammad Waqas/ Muzahir Ali (Lab Demo)
d) Submitted By: Individual Member Name with respective registration No.s
e) Date of Experiment Performed
f) Date of Report Submission
Objective
Describe briefly what are the main goals or learning outcome to perform this lab.
Introduction
Explain the theory behind the practical or experiment. It can include ideal diagrams used in
theory and graphs etc.
Express the goals and assigned tasks for the laboratory using your own words. What are you
given? What are you to find?
What are the applicable analytical representations, concepts, operations, and tools you have
learned from the text and lectures?
What did you learn from this assignment?
Preparation and Procedure
Approximately 1 page of text, providing answers to Laboratory Prep Problems if any.
Often performing the lab activity is facilitated by using your Lab Prep Problem solutions. How do
these solutions relate to the laboratory goals, tasks, and expected results?
Explain your sequence of steps used to achieve the objectives.
Describe the steps that you took and the results that you obtained for each step. Document your
observations in as much detail as possible. Include MATLAB output, screenshots or photos as
necessary.
Results
In this portion, you will show the results/MATLAB output that you obtained for each step. Document
your observations in as much detail as possible. Include MATLAB output or graphs that you obtained
from your experiment. Graphs should be of good resolution with appropriate axes information and
legends (if necessary).
Discussion
In this portion, you will describe what is achieved during experiment. Identify how variables that you
defined in the preparation section correspond to parameters. Mention the key points learned by you and
answer all the questions asked in this section. What difficulties did you encounter, if any? Be sure to
document how you overcame these. Even difficulties that seem to have trivial solutions, e.g., MATLAB
syntax errors, should be documented so that you do not continue to repeat them in future labs. Suggest
ways to improve your results.
Conclusions
Summarize your findings and discussion in ½ page.