0% found this document useful (0 votes)
8 views

MODULE+3+ +Roots+of+Non Linear+Equations+2023

This module covers the roots of non-linear equations, focusing on both bracketing and open methods for finding roots. It outlines expected learning outcomes, including the ability to solve root problems using various methods such as bisection, false-position, and Newton-Raphson. Additionally, it provides theoretical backgrounds, algorithms, and M-files for implementing these methods in MATLAB®.

Uploaded by

kkr5qwn9vp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

MODULE+3+ +Roots+of+Non Linear+Equations+2023

This module covers the roots of non-linear equations, focusing on both bracketing and open methods for finding roots. It outlines expected learning outcomes, including the ability to solve root problems using various methods such as bisection, false-position, and Newton-Raphson. Additionally, it provides theoretical backgrounds, algorithms, and M-files for implementing these methods in MATLAB®.

Uploaded by

kkr5qwn9vp
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 29

MODULE 3 – Roots of Non-Linear Equations 1

Engr. Caesar P. Llapitan

TOPICS
I. Roots: Bracketing Methods
II. Roots: Open Methods

EXPECTED LEARNING OUTCOMES


At the end of the module, the students should be able to:
1. Discuss what roots problems are and where they occur in engineering.
2. Solve root problems using the bracketing methods.
3. Differentiate bisection and false-position methods of solving roots of equation.
4. Solve root problems using the open methods.
5. Use simple fixed-point iterations and evaluate its convergence characteristics with
root problems.
6. Solve roots problem with the Newton-Raphson method and appreciating the
concept of quadratic convergence.
7. Implement secant method for evaluating the roots of an equation.
8. Formulate M-files for the bracketing and 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)

One of these methods is to use the quadratic formula

−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

Figure 1.0: Roots of an equation f(x)

II. BRACKETING METHODS

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

Figure 2A: A graphical depiction of the bisection method

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,

Step 5. Display the required root as c


Step 6. Stop
MODULE 3 – Roots of Non-Linear Equations 5
Engr. Caesar P. Llapitan

ii. General Flowchart

START Define the starting point of the


program.

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.

Input a, b, maxerr Putting in the parameters and


and other parameters the stopping criteria.

Computing for the root c using


the bisection method’s general
equation.

The value of variable b is


test < 0, b = c
assigned to variable c.

The value of variable a is


if test > 0, a = cif
assigned to variable c.

Process condition on whether


NO f ( c ) > maxerr using relational
> maxerr operators. If No, repeat arithmetic
operation of root c, if Yes,
proceed to the next step.

YES

Print c as solution Display of the output c

STOP Termination of Flow Chart

Chart 1: Bisection Method


MODULE 3 – Roots of Non-Linear Equations 6
Engr. Caesar P. Llapitan

iii. General M-file

M-file 2A: BisectionMfile.m

%% It will take function and initial value as the input of function.


% You would require to run it in command window as
% BisectionMfile(@(x)("Enter the Function"),a,b,maxerr);
% [a,b] initial values and maxerr is maximum error tolerable.

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

Figure 2B: A graphical depiction of the method of false position

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

This can be solved for

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 )

Step 4. Test for the accuracy of xr


MODULE 3 – Roots of Non-Linear Equations 8
Engr. Caesar P. Llapitan

if |f(xr)| > ea
test = f(xl)  f(xr)

if test < 0, then xu = xr;


elseif test > 0, then xl = xr;
else ea = 0,
Step 5. Display the required root as xr
Step 6. Stop
MODULE 3 – Roots of Non-Linear Equations 9
Engr. Caesar P. Llapitan

General Flowchart

Define the starting point of the


START program.

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.

Input xl, xu, ea and Putting in the parameters and


other parameters the stopping criteria.
parameter
Computing for the root c using
the secant method’s general
equation.

The value of variable xu is


test < 0, xu = xr
assigned to variable xr.

The value of variable xl is assigned


if test > 0, xl = xrif
to variable xr.

Process condition on whether


NO > ea using relational
> ea
operators. If No, repeat
arithmetic operation of root xr, if
Yes, proceed to the next step.
YES

Print xr as solution Display of the output xr

STOP Termination of Flow Chart

Chart 2: False Position


MODULE 3 – Roots of Non-Linear Equations 10
Engr. Caesar P. Llapitan

General M-file

M-file 2B: FalsePos.m

% 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)

xr = xu - f(xu)*(xl - xu) / (f(xl) - f(xu));


fl = f(xl)
fu = f(xu)
disp(' xl f(xl) xu f(xu) xr ');
disp([xl f(xl) xu f(xu) xr]);
while abs(f(xr))> ea
test = f(xl)*f(xr);
if test < 0
xu = xr;
fu = f(xu);
elseif test > 0
xl = xr;
fl = f(xl);
else
ea = 0;
end
xr = xu - f(xu)*(xl - xu) / (f(xl) - f(xu));
disp([xl f(xl) xu f(xu) xr]);
iter = 0;
iter = iter + 1;
if(iter == 100)
break;
end
end
display(['Root is x=' num2str(xr)]);
y=xr

III. OPEN METHODS

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.

A. Single-Fixed Point Iteration

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)

This transformation can be accomplished either by algebraic manipulation or by simply adding


x to both sides of the original equation. The utility of Eq. 3A.1 is that it provides a formula to
predict a new value of x as a function of an old value of x. Thus, given an initial guess at the root
xi, Eq. 3A.1 can be used to compute a new estimate xi + 1 as expressed by the iterative formula:

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)

Step 4. Display a and the root x(n)


Step 5. Stop.

General Flowchart

Defines the beginning of the


START program.

Preparation of memory space


n=0 for data processing. It also
represents the instructions
x (n) = 0 that will modify the program’s
course execution.

Inputting all the given


Input x(1), n and
parameters and the stopping
other parameters
criteria.
The general arithmetic
operations of single-fixed point
iteration where f ( x ( n ) ) is the
manipulated given function.

Print the n and x(n)as Display the output.


solution

Defines the end of the


STOP
program.

Chart 3: Single-Fixed Point Iteration


MODULE 3 – Roots of Non-Linear Equations 13
Engr. Caesar P. Llapitan

General M-file

M-file 3A: FixedPtIterMfile.m

%% Matlab m-file for Fixed-Point Iteration %%


%% To find the root of a given function in [0,1] %%
%% Matlab's default is 4 digits after the decimal %%
format short;
%% set initial guess - Matlab requires indices to start at 1 %%
x(1) = 3.5;
for n = 1:3

x(n+1) = %"Enter function"


disp ( ' n x(n+1) ' );
disp ( [ n x(n) ] );
x(n) =(x(n+1));
end

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 )

This is called the Newton-Raphson formula.

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

Step 5. Test for the accuracy of c

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

Designates the beginning of


START
the program
Preparation of memory space
a=0 for data processing. It also
c=0 represents the instructions
maxerr = 0 that will modify the program’s
course execution.

Inputting all the given


Input a, maxerr and
parameters and the stopping
other parameters
criteria.

The arithmetic operation of the


Newton-Raphson method for
calculating the root c.

The value of the variable a is


a=c
assigned to variable c.

Process conditions in whether


f ( c ) < maxerr using relational
NO <
operators. If No, repeat the
maxerr arithmetic operation of root c,
if Yes, proceed to the next step.

YES

Display the output.


Print solution

Designates the end of the


STOP program.

Chart 4: Newton-Raphson Method

General M-file
M-file 3B: NewtraphMfile.m

%% It will take function and initial value as the input of function.


% You would require to run it in command window as
% f = "Enter a function";
MODULE 3 – Roots of Non-Linear Equations 16
Engr. Caesar P. Llapitan

% df = "Enter the first derivative of the function";


% NewtraphMfile(f,df,a,maxerr)
% where f is function, [a] initial guess and maxerr is maximum error
tolerable.

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

A potential problem in implementing the Newton-Raphson method is the evaluation of the


derivative. Although this is not inconvenient for polynomials and many other functions, there
are certain functions whose derivatives may be difficult or inconvenient to evaluate. For these
cases, the derivative can be approximated by a backward finite divided difference:

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)

Step 5. Test for the accuracy of c


If f (c ) < maxerr

then assign a = b and b = 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 18
Engr. Caesar P. Llapitan

General Flowchart

Define the starting point of the


START program.

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.

Input a, b, maxerr Inputting the parameters and


and other parameters the stopping criteria.
parameter

Computing for the root c


using the secant method’s
general equation.

The value of variable a is


a=b
assigned to variable b.

The value of variable b is


b=c assigned to variable c.

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

Print c as solution Display the output c.

STOP STOP to terminate.

Chart 5: Secant Method


MODULE 3 – Roots of Non-Linear Equations 19
Engr. Caesar P. Llapitan

General M-file

M-file 3C: Secant Mfile.m

%% It will take function and initial value as the input of function.


% You would require to run it in command window as
% Secant_prob1 (@(x)("Enter the Function"),a,b,maxerr);
% [a,b] initial values and maxerr is maximum error tolerable.

function y = SecantMfile(f,a,b,maxerr)

c = (a*f(b) - b*f(a))/(f(b) - f(a));


disp(' Xn-1 f(Xn-1) Xn f(Xn) Xn+1
f(Xn+1)');
disp([a f(a) b f(b) c f(c)]);
while abs(f(c)) > maxerr
a = b;
b = c;
c = (a*f(b) - b*f(a))/(f(b) - f(a));
disp([a f(a) b f(b) c f(c)]);
iter = 3:1000;
iter = iter + 1;

if(iter == 100)
break;
end
end

display(['Root is x = ' num2str(c)]);


y = c;

IV. Numerical Examples

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 

9.81 m  9.81  0.25 


f ( m) = tanh   4  − 36 (b)
0.25  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 

substituting the given values

9.81 ( 80 )  9.81  0.25 


f ( m) = tanh   4  − 36
0.25  80 

Given the general formula of the Bisection Method

xr = (xl + xu)/2

The estimated root can be found.

M-file 5.1c: Bisection_Prob1.m

%% It will take function and initial value as the input of function.


% You would require to run it in command window as
% Bisection_Prob1 (@(x)(sqrt(9.81*80/x))*tanh(sqrt(9.81*x/80)*4)-
36,0.1,0.2,0.02;
% [0.1,0.2] initial values and maxerr is maximum error tolerable.

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%.

Hence for the sixth iteration,

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 
 

The first iteration is

−1.19738 ( 0.1 − 0.2 )


xr = 0.2 − = 0.141809
0.86029 − ( −1.19738 )

f ( 0.1 ) f ( 0.0141809 ) = 0.860291 ( −0.03521 ) = − 0.030292

Therefore, the root is in the first interval and the upper guess is redefined as xu = 0.141809.
The second iteration is

−0.03521 ( 0.1 − 0.141809 )


xr = 0.141809 − = 0.140165
0.86029 − ( −0.03521 )

0.140165 − 0.141809
ea = 100% = 1.17%
0.140165

M-file 5.1d: FP_Prob1.m

% 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)

xr = xu - f(xu)*(xl - xu) / (f(xl) - f(xu));


fl = f(xl)
fu = f(xu)
disp(' xl f(xl) xu f(xu) xr ');
disp([xl f(xl) xu f(xu) xr]);
while abs(f(xr))> ea
test = f(xl)*f(xr);
if test < 0
xu = xr;
fu = f(xu);
elseif test > 0
xl = xr;
fl = f(xl);
else
ea = 0;
end
MODULE 3 – Roots of Non-Linear Equations 23
Engr. Caesar P. Llapitan

xr = xu - f(xu)*(xl - xu) / (f(xl) - f(xu));


disp([xl f(xl) xu f(xu) xr]);
iter = 0;
iter = iter + 1;
if(iter == 100)
break;
end
end
display(['Root is x=' num2str(xr)]);
y=xr

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

M-file 5.2b: graph2.m

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

Single-Fixed Point Iteration

Solution
The general equation for the Simple Fixed-Point Iteration is

f ( x) =0

So, x is on the left side


x = g( x)

Given the function


f ( x ) = x 3 − 6 x 2 + 11 x − 6.1

Therefore
x 3 − 6 x 2 − 6.1 x 3 − 6 x 2 − 6.1
x= x=
−11 −11

M-file 5.2c: FixedPtIter_prob2.m

%% Matlab m-file for Fixed-Point Iteration %%


%% To find the root of f(x) = x^3-6*x^2+11*x-6.1 in [0,1] %%
%% Matlab's default is 4 digits after the decimal %%
format short;
%% set initial guess - Matlab requires indices to start at 1 %%
x(1) = 3.5;
for n = 1:3

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

Newton- Raphson Method

Solution
The general equation for the Newton-Raphson Method is
f (x)
xi + 1 = x −
f '( x )

Given the function f ( x ) = x 3 − 6 x 2 + 11 x − 6.1

Its first-order derivative is calculated as f ' ( x ) = 3 x 2 − 12 x + 11

Substituting it to Eq. (2.1b),

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

Starting with an initial value of xi = 3.5.

M-file 5.2d: Newtraph_prob2

%% It will take function and initial value as the input of


function.
% You would require to run it in command window as
% f = @(t) x^3-6*x^2+11*x-6.1;
% df = @(t)3*x^2-12*x+11;
% Newtraph_prob3(f,df,0,0.0001)
% where x^3-6*x^2+11*x-6.1 is function, [3.5] initial guess and
0.0001 is maximum
% error tolerable.
function y = Newtraph_prob2(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;
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 )

Given the function f ( x ) = x 3 − 6 x 2 + 11 x − 6.1

By substituting it to Eq. (2.1c),

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

%% It will take function and initial value as the input of function.


% You would require to run it in command window as
% Secant_prob2 (@(x)(x^3-6*x^2+11*x-6.1),2.5,3.5,0.0001);
% where @(x)x^3-6*x^2+11*x-6.1 is function, [2,5,3.5] initial values
and 0.0001 is maximum
% error tolerable.

function y = Secant_prob2(f,a,b,maxerr)

c = (a*f(b) - b*f(a))/(f(b) - f(a));


MODULE 3 – Roots of Non-Linear Equations 28
Engr. Caesar P. Llapitan

disp(' Xn-1 f(Xn-1) Xn f(Xn) Xn+1 f(Xn+1)');


disp([a f(a) b f(b) c f(c)]);
while abs(f(c)) > maxerr
a = b;
b = c;
c = (a*f(b) - b*f(a))/(f(b) - f(a));
disp([a f(a) b f(b) c f(c)]);
iter = 3:1000;
iter = iter + 1;

if(iter == 100)
break;
end
end

display(['Root is x = ' num2str(c)]);


y = c;

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.

You might also like