MODULE+3+ +Roots+of+Non Linear+Equations+2023
MODULE+3+ +Roots+of+Non Linear+Equations+2023
TOPICS
I. Roots: Bracketing Methods
II. Roots: Open Methods
I. INTRODUCTION
During our high school days, we learned different methods in how to calculate
f ( x ) = ax 2 + bx + c = 0 (1.0)
−b b2 − 4ac
x= (1.1)
2a
whenever we can’t find the factors of f(x). We can observe from Eq. 1.0 that f(x) = 0. It is the
reason why the x values can be calculated through Eq. 1.1. The “roots” of Eq. 1.0 are the values of
x calculated from Eq. 1.0, also referred to as the zeroes of an equation. Nevertheless, these roots
are not only limited to the quadratic formula, in the fields of engineering and sciences, its
applications range from heat balance, mass balance, force balance and energy balance to
Newton’s law of motion and Kirchhoff’s laws. By studying it, we gain further understanding on
how we want to apply it in real world problems.
Graphically, the roots are portrayed in Fig. 1.0 in which they are found in the x-axis, making the
f(x) equivalent to zero. In the past, one of the ways to find the root is by locating it in the graph
and through trial-and-error calculations, however, the values obtained are not accurate since
they are solely rough estimates. Due to this, various methods are formulated to solve the roots
of nonlinear equations. Now, with the power of computers, solving roots can be easily done
through diverse mathematical software. In particular, we describe MATLAB®’s excellent built-
in capabilities for this task. With the combination of manual calculations and this software, we
acquaint you with different methods for finding the root of a single nonlinear equation.
MODULE 3 – Roots of Non-Linear Equations 2
Engr. Caesar P. Llapitan
If you had a roots problem in the days before computing, you do often be told to use trial and
error to come up with the root. That is, you do repeatedly make guesses until the function was
sufficiently close to zero. The process was greatly facilitated by the advent of software tools such
as spreadsheets. By allowing you to make many guesses rapidly, such tools can actually make
the trial-and-error approach attractive for some problems. But, for many other problems, it is
preferable to have methods that come up with the correct answer automatically. Interestingly,
as with trial and error, these approaches require an initial guess to get started. Then they
systematically home in on the root in an iterative fashion.
A. Bisection Method
Theoretical Background
The bisection method, which is alternatively called binary chopping, interval halving, or
Bolzano’s method, is one type of incremental search method in which the interval is always
divided in half. If a function changes sign over an interval, the function value at the midpoint is
evaluated. The location of the root is then determined as lying at the midpoint of the subinterval
within which the sign change occurs. The process is repeated to obtain refined estimates.
We attempt to find by inspection, or trial and error, two values of x, call them xl and xu, such
that f(xl) and f(xu) have different signs, i.e. f(xl)f(xu)<0. If we can find two such values, the root
must lie somewhere in the interval between them, since f(x) changes sign on this interval (Fig.
2A)
MODULE 3 – Roots of Non-Linear Equations 3
Engr. Caesar P. Llapitan
In the Bisection method, we estimate the root by xr, where xr is the mid-point of the interval [xl,
xu],
xl + xu
xr = (2A.1)
2
Then if f(xr) has the same sign as f(xl), as drawn in the figure, the root clearly lies between xr
and xl. We must then redefine the left-hand end of the interval as having the value of xr, we let
the new value of xl be xr. Otherwise, if f(xr) and f(xl) have different signs, we let the new value
of xu be xr, since the root must lie between xl and xr in that case. Having redefined xl or xr, as
the case may be, we bisect the new interval again according to Equation (2A.1) and repeat the
process until the distance between xl and xr is as small as we please.
We can calculate how many bisections are needed to obtain a certain accuracy, given initial
values of xl and xu. Suppose we start with xl = a, and xu = b. After the first bisection the worst
possible error (E1) in xr is E1 = |a − b|/2, since we are estimating the root as being at the mid-
point of the interval [a, b]. The worst that can happen is that the root is actually at xl or xu, in
which case the error is E1. Carrying on like this, after n bisections the worst possible error En is
given by En = |a − b|/2n. If we want to be sure that this is less than some specified error E, we
must see to it that n satisfies the inequality |a − b|/2n < E.
a−b
log
n E (2A.2)
log 2
Since n is the number of bisections, it must be an integer. The smallest integer n that exceeds
the right-hand side of Inequality (Eq. 2A.2) will do as the maximum number of bisections
required to guarantee the given accuracy E.
MODULE 3 – Roots of Non-Linear Equations 4
Engr. Caesar P. Llapitan
Numerical Analysis
i. General Algorithm
Step 1. Start
Step 2. Input the values a, b and maxerr.
- *a and b are upper and lower boundary, respectively and maxerr is the
absolute maximum error used to stop the criteria.*
a+b
Step 3. Compute c =
2
Step 4. Test for the accuracy of c
if |f(c)| > maxerr
test = f(a)*f(c)
if test < 0, then b = c;
elseif test > 0, then a= c;
else maxerr = 0,
Preparation or initialization of
a= 0, b= 0 memory space for data processing. It
maxerr = 0 also represents instructions that will
modify the program’s course
execution.
YES
function y = BisectionMfile(f,a,b,maxerr)
c=(a+b)/2;
disp(' xl xu xr ');
disp([a b c ]);
while abs(f(c))> maxerr
test = f(a)*f(c);
if test < 0
b = c;
elseif test > 0
a = c;
else
maxerr = 0;
end
c=(a+b)/2;
disp([a b c ]);
iter=0;
iter=iter+1;
if(iter==50)
break;
end
end
display(['Root is x=' num2str(c)]);
y=c
B. False Position
Theoretical Background
A shortcoming of the bisection method is that, in dividing the interval from xl to xu into equal
halves, no account is taken of the magnitudes of f(xl) and f(xu). For example, if f(xl) is much
closer to zero than f(xu), it is likely that the root is closer to xl than to xu (Figure 2B). An
alternative method that exploits this graphical insight is to join f(xl) and f(xu) by a straight line.
The intersection of this line with the x axis represents an improved estimate of the root. The
fact that the replacement of the curve by a straight line gives a “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.
MODULE 3 – Roots of Non-Linear Equations 7
Engr. Caesar P. Llapitan
Using similar triangles (Figure 2B), the intersection of the straight line with the x axis can be
estimated as
f ( xl ) f ( xu )
= (2B.1)
xr − xl xr − xu
f ( xu ) xl − xu
xr = xu − (2B.2)
f ( xl ) − f ( x u )
This is the false-position formula. The value of xr computed with Eq. 2B.B then replaces
whichever of the two initial guesses, xl or xu, yields a function value with the same sign as f(xr).
In this way, the values of xl and xu always bracket the true root. The process is repeated until
the root is estimated adequately.
Numerical Analysis
General Algorithm
Step 1. Start
Step 2. Input the values xl, xu and ea.
- *xl and xr are upper and lower boundary of x, respectively and ea is the
absolute maximum error used to stop the criteria.*
f ( xu ) xl − xu
Step 3. Compute xr = xu −
f ( xl ) − f ( x u )
if |f(xr)| > ea
test = f(xl) f(xr)
General Flowchart
Preparation or initialization of
memory space for data processing. It
xl = 0, xu = 0
also represents instructions that will
ea = 0
modify the program’s course
execution.
General M-file
% uses the false position method to find the root of the function func
%You would require to run it in command window as
% FalsePos(@(x)("Enter the Function"),xl,xu,ea);
% xl, xu = lower and upper guesses
% ea = approximate relative error (%)
function y = FalsePos(f,xl,xu,ea)
Open methods described in this chapter require only a single starting value or two starting
values that do not necessarily bracket the root. As such, they sometimes diverge or move away
from the true root as the computation progresses. However, when the open methods converge,
they usually do so much more quickly than the bracketing methods. We will begin our
discussion of open techniques with a simple approach that is useful for illustrating their general
form.
Theoretical Background
Iteration method, also known as the fixed-point iteration method, is one of the most popular
approaches to find the real roots of a nonlinear function. It requires just one initial guess and
has a fast rate of convergence which is linear.
MODULE 3 – Roots of Non-Linear Equations 11
Engr. Caesar P. Llapitan
As just mentioned, open methods employ a formula to predict the root. Such a formula can be
developed for simple fixed-point iteration (or, as it is also called, one-point iteration or
successive substitution) by rearranging the function f ( x ) = 0 so that x is on the left-hand side
of the equation:
x = g( x ) (3A.1)
xi + 1 = g ( xi ) (3A.2)
As with many other iterative formulas, the approximate error for this equation can be
determined using the error estimator:
xi + 1 − xi
a = 100 % (3A.3)
xi + 1
Figure 3A: Graphical depiction of (a) and (b) convergence and (c) and (d) divergence of simple fixed-
point iteration. Graphs (a) and (c) are called monotone patterns
whereas (b) and (c) are called oscillating or spiral patterns.
MODULE 3 – Roots of Non-Linear Equations 12
Engr. Caesar P. Llapitan
Numerical Analysis
General Algorithm
Step 1. Start
Step 2. Input x(1), n and other given parameters.
*Where, x(1) is the value of initial guess while n is the number of iterations *
Step 3. Compute x = (n + 1)
General Flowchart
General M-file
B. Newton-Raphson Method
Theoretical Background
One of the problems in practical operations is root finding. Newton-Raphson method is the
most widely used of all root-locating formulas because it is a very fast and effective as compared
to the other methods. It is based on the simple idea of linear approximation like the differential
equation.
Figure 3B: Graphical depiction of the Newton-Raphson method. A tangent to the function of
xi [that is, f '(x)] is extrapolated down to the x axis to provide an estimate of the root at xi+1.
In Figure 3B, the Newton-Raphson method can be derived by using the slope (tangent) of the
function f(x) at the current iterative solution (xi) to find the solution (xi) in the next iteration.
The slope ( xi , f ( xi ) ) is given by
f ( xi ) − 0
f ' ( xi ) = (3B.1)
xi − xi + 1
And rearranged to
MODULE 3 – Roots of Non-Linear Equations 14
Engr. Caesar P. Llapitan
f ( xi )
xi + 1 = xn − , i = 0, 1, ... (3B.2)
f 1 ( xi )
Numerical Analysis
General Algorithm
Step 1. Start
Step 2. Input the values of a, maxerr and other given parameters.
*Here , a is the value of the initial guess while maxerr is the stopping
criteria, absolute error or the desired degree of accuracy*
Step 3. Compute f(a) and df(a)
f (a )
c=a
df (a )
Step 4. Compute
If f (c ) < maxerr
then assign a =c
go to step 4
Else,
go to step 6
Step 6. Display the required root as c.
Step 7. Stop.
MODULE 3 – Roots of Non-Linear Equations 15
Engr. Caesar P. Llapitan
General Flowchart
YES
General M-file
M-file 3B: NewtraphMfile.m
function y = NewtraphMfile(f,df,a,maxerr)
c = (a)-(f(a)/df(a));
disp(' Xn f(Xn) df(Xn) Xn+1 ');
disp([a f(a) df(a) c]);
while abs(f(c)) > maxerr
a = c;
c = (a)-(f(a)/df(a));
disp([a f(a) df(a) c]);
iter = 0;
iter = iter + 1;
if(iter == 100)
break;
end
end
y = c;
C. Secant Method
Theoretical Background
f ( xi −1 ) − f ( xi )
f '( x ) (3C.1)
xi −1 − xi
This approximation can be substituted into Eq. (3C.1) to yield the following iterative equation:
f ( xi )( xi −1 − xi )
xi + 1 = xi − (3C.2)
f ( xi −1 ) − f ( xi )
Equation (3C.2) is the formula for the secant method. Notice that the approach requires two
initial estimates of x. However, because f (x) is not required to change signs between the
estimates, it is not classified as a bracketing method.
Numerical Analysis
General Algorithm
Step 1. Start
Step 2. Input the values a, b, maxerr and other parameters.
MODULE 3 – Roots of Non-Linear Equations 17
Engr. Caesar P. Llapitan
Here a and b are the two initial guesses, maxerr is the stopping criteria,
absolute error or the desired degree of accuracy.
Step 3. Compute f(a) and f(b).
a f (b) − b f (a)
Step 4. Compute c =
f (b) − f (a)
General Flowchart
Preparation or initialization of
memory space for data
a = 0, c = 0, b = 0, processing. It also represents
maxerr = 0 instructions that will modify the
program’s course execution.
Process condition on
whether f (c) < maxerr
NO using relational operators. If
< maxerr No, repeat arithmetic
operation of root c, if Yes,
proceed to the next step.
YES
General M-file
function y = SecantMfile(f,a,b,maxerr)
if(iter == 100)
break;
end
end
Problem 1
Use bisection method and false position to determine the drag coefficient needed so that an
80-kg bungee jumper has a velocity of 36 m/s after 4s of free fall. Note: The acceleration of
gravity is 9.81m/s2. Start with initial guesses of xl =0.1 and xu =0.2 and iterate until the
approximate relative error falls below 2%.
1. Mathematical Model
gm gc
f ( m) = tanh d t − v (t ) (a)
cd m
where:
cd = drag coefficient
g = acceleration due to gravity
v(t) = velocity
t = time of free fall.
m = mass of the bungee jumper
MODULE 3 – Roots of Non-Linear Equations 20
Engr. Caesar P. Llapitan
2. Graph
M-file 5.1b: graph1.m
As shown in the graph above, when mass is 80 kg, the cd is approximately 0.14.
Bisection Method
Solution
The function to evaluate is
gm gc
f ( m) = tanh d t − v (t )
cd m
xr = (xl + xu)/2
function y = Bisection_Prob1(f,a,b,maxerr)
c=(a+b)/2;
disp(' xl xu xr ');
disp([a b c ]);
while abs(f(c))> maxerr
test = f(a)*f(c);
MODULE 3 – Roots of Non-Linear Equations 21
Engr. Caesar P. Llapitan
if test < 0
b = c;
elseif test > 0
a = c;
else
maxerr = 0;
end
c=(a+b)/2;
disp([a b c ]);
iter=0;
iter=iter+1;
if(iter==50)
break;
end
end
display(['Root is x=' num2str(c)]);
y=c
MATLAB® Output
Summary
After five iterations, we obtain a root estimate cd of 0.14063 having an approximate relative
percent error of above 2%. Since it is still above, we can still do an additional iteration until
we obtain an approximate relative percent error of below 2%.
0.1375 + 0.140625
xr = = 0.1390625
2
0.1390625 − 0.140625
ea = 100% = 1.12%
0.1390625
MODULE 3 – Roots of Non-Linear Equations 22
Engr. Caesar P. Llapitan
At 6th iteration the required approximate relative percent error which is below 2% is finally
achieved. The true percentage relative error from the theoretical root is 0.67%.
False Position
Solution
The function to evaluate is
9.81(80) 9.81 cd
f ( cd ) = tanh 4 − 36
cd 80
Therefore, the root is in the first interval and the upper guess is redefined as xu = 0.141809.
The second iteration is
0.140165 − 0.141809
ea = 100% = 1.17%
0.140165
% uses the false position method to find the root of the function
func
%You would require to run it in command window as
% FP_Prob1(@(@(x)(sqrt(9.81*80/x))*tanh(sqrt(9.81*x/80)*4)-
36,0.1,0.2,0.02;
% xl, xu = lower and upper guesses(0.1,0.2)
% ea = approximate relative error (%)
function y = FP_Prob1(f,xl,xu,ea)
MATLAB® output:
Summary
After only two iterations we obtain a root estimate of 0.140165 with an approximate error of
1.17% which is below the stopping criterion of 2%. The true percentage relative error is equal to
0.12%.
Conclusion
Using the graph1.m, the theoretical value of cd is equal to 0.14 in 80 kg mass. In the bisection
method cd is computed at the 6th iteration with a value of 0.1390625. It has an approximate error
of 1.12% and a true percentage relative error of 0.67%. While cd is immediately obtained after
only two iterations in false position with a value of 0.140165, approximate error of 1.17% and true
MODULE 3 – Roots of Non-Linear Equations 24
Engr. Caesar P. Llapitan
percentage relative error of 0.12%. This proves that the calculated cd value of false position is
more accurate.
Problem 2
Determine the highest real root of f ( x ) = x 3 − 6 x 2 + 11 x − 6.1 :
a. Using the Single-Fixed Point iteration (three iterations, x(i) =3.5).
b. Using the Newton-Raphson method (three iterations, xi = 3.5 ).
c. Using the Secant method (three iterations, x(i−1) =2.5 and x(i) =3.5)
1. Mathematical Model
f ( x ) = x 3 − 6 x 2 + 11 x − 6.1
2. Graph
Figure 2.1: The roots are located approximately at 1.05, 1.9 and 3.05. From the range of
2.5 x 3.5 the root is approximately 3.05.
MODULE 3 – Roots of Non-Linear Equations 25
Engr. Caesar P. Llapitan
Solution
The general equation for the Simple Fixed-Point Iteration is
f ( x) =0
Therefore
x 3 − 6 x 2 − 6.1 x 3 − 6 x 2 − 6.1
x= x=
−11 −11
x(n+1) = (x(n)^3-6*x(n)^2-6.1)/-11;
disp ( ' n x(n+1) ' );
disp ( [ n x(n) ] );
x(n) =(x(n+1));
end
MATLAB® Output:
Summary
After third iteration the calculated root was 3.2514 which have true percent relative error of
6.3%.
MODULE 3 – Roots of Non-Linear Equations 26
Engr. Caesar P. Llapitan
Solution
The general equation for the Newton-Raphson Method is
f (x)
xi + 1 = x −
f '( x )
x 3 − 6 x 2 + 11 x − 6.1 2 x 3 − 6 x 2 + 6.1
xi + 1 = x − xi + 1 =
3 x 2 − 12 x + 11 3 x 2 − 12 x + 11
c = (a)-(f(a)/df(a));
disp(' Xn f(Xn) df(Xn) Xn+1 ');
disp([a f(a) df(a) c]);
while abs(f(c)) > maxerr
a = c;
c = (a)-(f(a)/df(a));
disp([a f(a) df(a) c]);
iter = 0;
iter = iter + 1;
if(iter == 100)
break;
end
end
y = c;
MODULE 3 – Roots of Non-Linear Equations 27
Engr. Caesar P. Llapitan
MATLAB® Output:
Summary
After the fourth iteration, the calculated root was 3.0467 which have true percent error
of 0.0001%.
Secant Method
Solution
The general equation for the Secant Method is
f ( xi )( xi −1 − xi )
xi + 1 = xi −
f ( xi −1 ) − f ( xi )
xi + 1 = xi −
(x 3
i )
− 6 xi2 + 11 xi − 6.1 ( xi − 1 − xi )
(x
3
i −1 ) (
− 6 xi2− 1 + 11 xi − 1 − 6.1 − xi3 − 6 xi2 + 11 xi − 6.1 )
M-file 5.2e: Secant_prob2.m
function y = Secant_prob2(f,a,b,maxerr)
if(iter == 100)
break;
end
end
MATLAB® Output:
Summary
The calculated root, 3.0467, has 0.0001 true percent relative error after 7 iterations.
Conclusion
After the third iteration, the calculated root of Single-Fixed Point Iteration was 3.2514
which have true percent relative error of 6.3%. In Newton-Raphson Method, the calculated
root was 3.0467 after the fourth iteration with a true percent error of 0.0001%. And lastly,
the Secant Method has a calculated root of 3.0467, 0.0001 true percent relative error and 7
iterations. Comparing the three methods, the Single-Fixed Point Iteration has the least
accuracy while the Newton-Raphson is the most efficient and accurate.
MODULE 3 – Roots of Non-Linear Equations 29
Engr. Caesar P. Llapitan
REFERENCES
[1] Chapra, S. C. (2012). Applied Numerical Methods with MATLAB® for Engineers and
Scientists. In Open Methods (Third ed., pp. 151-181). McGraw-Hill Companies,Inc.
[2] Chapra, S. C. (2012). Applied Numerical Methods with MATLAB® for Engineers and
Scientists. In Bracketing Method (Third ed., pp. 126-150). McGraw-Hill Companies,
Inc.
[3] Chapra, S. C. (2012). Applied Numerical Methods with MATLAB® for Engineers and
Scientists. In Roots and Optimization (Third ed., pp. 123-125). McGraw-Hill
Companies, Inc.
[4] Kreysig, E. (2011). Avanced Engineering Mathematics. In Solutions of Equations by
Iteration (Tenth ed., pp. 798-807). RR Donnelley and Sons Company.
[5] Steven C. Chapra and Raymond Canale. (2002). Numerical Methods for Engineers.
McGraw-Hill Companies, Inc.