You are on page 1of 9

School of Chemical and Biomedical Engineering

BG2802

Solution of Roots of Equations


(Computing)

Location: N1.3-B4-02

Name: _______________________________________

Matric Number: _______________________________________

Group: _______________________________________

Date of experiment: _______________________________________

GRADE: _____________
1. INTRODUCTION

The aim of this practical is to develop programs using MATLAB for finding numerical
approximations for the roots of non-linear equation. Specifically, Newton-Raphson
method will be implemented.

2. OBJECTIVES

In this practical, you will

1. Learn to use MATLAB to find the roots of equation using Newton-Raphson


method.

2. Find the solution to a molecular bioengineering problem using Newton Raphson


method.

3. BACKGROUND

3.1 Newton-Raphson Method:

The Newton-Raphson method is one of the most useful algorithms that relies on the
continuity of f’(x) and f’’(x). The Newton-Raphson method approximates a root of f(x)
= 0 using an initial approximation p0 and using the iteration formula given:

𝑓(𝑝𝑘−1 )
𝑝𝑘 = 𝑝𝑘−1 − for k = 1, 2, …
𝑓 ′ (𝑝𝑘−1 )

3.1.1 Geometric Description of Newton-Raphson Method

Figure 1 illustrates the geometric construction of p1 and p2 for the Newton-Raphson


method. For the purpose of illustration, assume that the initial approximation p0 is near
the root p. Hence, the graph of y = f(x) intersects the x-axis at the point (p, 0) and the
point (p0 , f(p0)) lies on the curve near the point (p,0) as shown in Figure 1. Referring to
the figure, p1 is the point of intersection of the x-axis and the line tangent to the curve
at the point (p0, f(p0)). In this case shown in the figure, p1 will be closer to p than p0.

An equation relating p1 and p0 can be derived by using two versions for the slope of the
tangent line L:

0 − 𝑓(𝑝0 )
𝑚= (1)
𝑝1 − 𝑝0

Which is the slope of the line through (p1, 0) and (p0, f(p0) ), and

1
𝑚 = 𝑓 ′ (𝑝0 ) (2)

Which is the slope at the point (p0, f(p0) ).

By equating the values of the slope m in equations (1) and (2) and solving for p1, the
equation relating p1 and p0 would be:

𝑓(𝑝0 )
𝑝1 = 𝑝0 − (3)
𝑓 ′ (𝑝0 )

The process described can be repeated to obtain a sequence {pk} that converges to p.

Figure 1. The geometric construction of p1 and p2 for the Newton-Raphson method.

3.1.2 The Algorithm

The steps to apply Newton-Raphson method to find the root of an equation f(x) = 0 are
as follow:

1. Derive f ‘(x)

2. Use an initial guess of the root, pk-1, to estimate the new value of the root pk as

𝑓(𝑝𝑘−1 )
𝑝𝑘 = 𝑝𝑘−1 − for k = 1, 2, …
𝑓(𝑝𝑘 )

3. Find the absolute relative approximate error, | ∈𝑎 | as

𝑝𝑘 − 𝑝𝑘−1
| ∈𝑎 | = | |
𝑝𝑘

2
4. Compare the absolute relative approximate error, | ∈𝑎 | with the pre-defined
relative error tolerance, ∈𝑠 . If |∈𝑎 | > ∈, or the number of iterations has not
exceeded the maximum number of iterations, repeat step 2, else stop the
algorithm.

3.1.3. Drawbacks of Newton-Raphson method

The method suffers from a number of drawbacks:

1. Divergence at inflection points: If the selection of an initial estimate turns out


to be near to the inflection point of f(x) (i.e. where f’(x) = 0), the solution will
diverge away from the root.

2. Division of zero or near zero: If an iteration value, pk is such that f’(pk) ≈ 0,


then one can face division by zero or a near-zero number. This will give a large
value for the next iteration value, pk+1. This would be undesirable.

3. Root Jumping: For function f(p) that oscillates and has a number of roots, an
initial estimate may have been chosen to be close to a root. However, the
estimate may jump and converge to some other root.

3.2. Molecular Bioengineering

In this practical we will study a molecular bioengineering problem involving the


solution of a Michaelis-Menten Kinetics equation using the Newton-Raphson method.

Enzymes are proteins which perform as catalysts and generally act on substrates with
high specificity. The consumption of a substrate source can be described by the kinetic
depletion of the substrate in terms of the enzyme activity. The kinetics of enzyme
reactions can be formulated in terms of the Michaelis-Menten model, given as:

𝑑𝑠 𝑉𝑚𝑎𝑥 𝑠
𝑟𝑠 = − =
𝑑𝑡 𝐾𝑚 + 𝑠
Where
 rs is the reaction rate of the substrate in moles/volume/time;
 s is the substrate concentration in moles/volume;
 Vmax is the maximal substrate consumption rate;
 Km is the concentration of the substrate that elicits half-maximal consumption
rate.

The analytical non-linear solution for the substrate concentration as a function of time
is given as:
𝑠0
𝐾𝑚 log ( ) + (𝑠0 − 𝑠) = 𝑉𝑚𝑎𝑥 𝑡
𝑠

3
Where

 s is the substrate concentration at any time t;


 s0 is the initial substrate concentration.

In this practical we will use the Newton-Raphson method to determine the


concentration of substrate, s, which depletes over time due to a given enzyme.

4. EQUIPMENT

 Personal computer
 MATLAB software (Ver. 2019)

5. EXERCISE

1. First, create a new folder “Roots of Equations” in your network directory. This
folder will be your working directory where you will save all the programs written
in this practical. Now specify the MATLAB working directory as your new folder,
as illustrated in Figure 2. Remember to save all the files in this folder.

Right click in your network directory to create


a new folder “Roots of Equations”

Figure 2. Defining working directory in MATLAB

2. Create a new .m file and save as Newton1.m

Steps for creating the new .m file

Go to Home tab and select New Script icon or New icon followed by Script. A
new window called untitled will open. In Editor Tab, select Save and a dialog

4
box will open with a default entry untitled.m. Replace that with Newton1.m and
click Save as you did before. Save the file into the working directory. (Be sure
to save your work when you have finished typing.)

3. Enter the following code into Newton1.m. Remember to save your work along the
way:
% func is the object function
% dfunc is the derivative of func
% p0 is the initial approximation to a zero of f
% maxIteration is the maximum number of iterations
% tolerance is the desirable tolerance
% func and dfunc are defined as M-file functions

clear all;

maxIteration = 5;
p0 = 0.05;
tolerance = 0.0001;
for k = 1 : maxIteration
p1 = p0 – func1(p0)/dfunc1(p0); %Q1:what is the function?
fprintf(' k=%3.0f, p0 =%12.5e, p1 = %12.5e, ', k, p0, p1);
%Q2:what is the function?
absrelerr = abs(p1 - p0)/abs(p1);
p0=p1;
fprintf(' Absolute relative approximate error = %12.5e \n',
absrelerr);
if(absrelerr < tolerance), break, end
end
fprintf('End\n\n');
fplot(@(x) x.^3 - 0.165*x^.2 + 0.0003993, [-0.1 0.2]); grid on
title(['Newton 1 by STUDENT NAME']);

You may have noticed that Newton1.m file calls two functions, (i.e. func1 and
dfunc1). func1 function defines the f(x) equations that need to be solved and dfunc1
function define the derivative of f(x). We will create the two functions in the next
section by working on an exercise.

A. EXERCISE ONE

1. Consider the equation

𝑥 3 − 0.165𝑥 2 + 3.993𝑥10−4 = 0

Estimate the root of the above equation.

Since

𝑓(𝑥) = 𝑥 3 − 0.165𝑥 2 + 3.993𝑥10−4

5
Show that the derivative of the above equation is

𝑓 ′ (𝑥) = 3𝑥 2 − 0.33𝑥

We will create the two .m files that contain the equations that we have derived above.

2. Create a new .m file and save as func1.m. Enter the following code.
function y = func1(x);

y = x^3 - 0.165*x^2 + 0.0003993;

3. Now create another new .m file and save as dfunc1.m. This file contains the
derivative of the function f(x). Enter the following code.
function y = dfunc1(x);

y = 3*x^2 - 0.33*x;

4. Run Newton1.m file by typing the following command in the command window in
Matlab, as illustrated in Figure 2.

>> Newton1

Note: It is case sensitive.

Figure 3. Running a .m file, e.g. Netwon1.m

5. Answer the questions Q1 and Q2 inside the code. Write your answers as comments
in the code. Note down the values of x at iteration 1, 2 and 3; check your results
with the TA to make sure that it is right before proceeding to the Exercise Two.

6
B. EXERCISE TWO

1. As described in the introduction, the analytical solution of the Michaelis-Menten


model is given by:
𝑠0
𝐾𝑚 log ( ) + (𝑠0 − 𝑠) − 𝑉𝑚𝑎𝑥 𝑡 = 0
𝑠
Show that the first derivative of the equation is

1
𝑓 ′ (𝑠) = −𝐾𝑚 ( ) − 1
𝑠
Using the following values for the variables

Km = 0.5 mM;
Vmax = 5.0 mM/min;
s0 = 1.0 mM;

Find the substrate concentration when time t = 0, 5, 30 minute using the Newton-
Raphson method. You may like to use the initial estimate of 0.95, 0.80, 0.20 at t =
0, 5, 30 minute respectively.

Time t Substrate
0 Concentration, s
5
30

2. Hint:
𝑠0
𝑓(𝑠) = 𝐾𝑚 log ( ) + (𝑠0 − 𝑠) − 𝑉𝑚𝑎𝑥 𝑡
𝑠
3. Create a new .m file and save as func2.m and enter the following code:

function y = func2(s, t, Km, so, vmax);

y = Km*log(so/s) + (so - s) - vmax*t;

4. Create another .m file and save as dfunc2.m and enter the following code:
function y = dfunc2(s, Km);

y = -Km*(1/s) - 1;

5. Create a new .m file and save as Newton2.m and enter the following code. The code
is similar to Newton1.m which you have created in Exercise One. The only
difference is now this code is calling func2 and dfunc2 instead of func1 and dfunc1.
Replace YOUR_INITAL_ESTIMATE with the initial estimate value at each time
t that you are running.

7
clear all;

maxIteration = 10;
p0 = YOUR_INITAL_ESTIMATE;
tolerance = 0.0001;

t = 0; %Time
so = 1.0; %initial substrate concentration
vmax = 0.05; %maximal substrate consumption rate
Km = 0.5; %Concentration of the substrate that
elicit half-maximal consumption rate

for k = 1 : maxIteration
p1 = p0 - func2(p0, t, Km, so, vmax)/dfunc2(p0, Km);
fprintf('k=%3.0f, p0 =%12.5e, p1 = %12.5e, ', k, p0, p1);
absrelerr = abs(p1 - p0)/abs(p1);
p0=p1;
fprintf(' Absolute relative approximate error = %12.5e \n',
absrelerr);
if(absrelerr < tolerance), break, end

end

fprintf('End\n\n');
fplot(@(x) (0.5*log(1./x)+(1-x))./0.05, [0 1]); grid on
title(['Newton 2 by STUDENT NAME']);

REFERENCES

1. Dunn S. M., Constantinides A, Moghe R. V. Numerical Methods in


Biomedical Engineering, Academic Press Series in Biomedical
Engineering, 2006.

You might also like