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

Numerical-Analysis-Report-To-Submit

This report from the Ho Chi Minh City University of Technology presents a computing program focused on numerical analysis, specifically solving equations in one variable using various methods. It covers three methods: the Bisection Method, Fixed-Point Iteration, and Newton's Method, detailing theorems, programming codes, and examples for each. The document is structured with contributions from multiple students and includes a table of contents for easy navigation.

Uploaded by

Khoa Vu
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)
9 views

Numerical-Analysis-Report-To-Submit

This report from the Ho Chi Minh City University of Technology presents a computing program focused on numerical analysis, specifically solving equations in one variable using various methods. It covers three methods: the Bisection Method, Fixed-Point Iteration, and Newton's Method, detailing theorems, programming codes, and examples for each. The document is structured with contributions from multiple students and includes a table of contents for easy navigation.

Uploaded by

Khoa Vu
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/ 13

HO CHI MINH CITY UNIVERSITY OF TECHNOLOGY

COMPUTING PROGRAM REPORT


NUMERICAL ANALYSIS
Lecturer: Phan Thành An
Class: CC03

GROUP 1
(Topic 1: Solve Equations in 1 Variable Using Different Methods)

Mikaelah Perez MSSV: 2052818


Nguyễn Đình Tuấn MSSV: 1953072
Lê Phương Nguyên MSSV: 1952881
Hà Khánh Duy MSSV: 2052909
Vũ Anh Khoa MSSV: 2053157
Lê Hồng Phúc MSSV: 2053337
Table of Contents

Types of Method Page Number

Method #1: The Bisection Method 1


Theorem …………………………………………………
(Contributed by Mikaelah Perez)

Programming Code ………………………………………………… 2


(Contributed by Nguyễn Đình Tuấn)

Example ………………………………………………… 3

Method #2: Fixed – Point Iteration 5


Theorem …………………………………………………
(Contributed by Lê Phương Nguyên)

Programming Code …………………………………………………


(Contributed by Hà Khánh Duy)

Example ………………………………………………… 6

Method # 3: Newton’s Method 8


Theorem …………………………………………………
(Contributed by Vũ Anh Khoa)

Programming Code ………………………………………………… 9


(Contributed by Lê Hồng Phúc)

Example …………………………………………………

References ………………………………………………… 11

i
Numerical Analysis Computing Program Report

Method #1 of Finding the Root of One Variable Solution:


The Bisection Method
(Contribution by: Mikaelah Perez & Nguyễn Đình Tuấn)

I. THEOREM

The Bisection Method, also called the Binary-Search Method, is based on the Intermediate
Value Theorem. It is based on the process of dividing a set continually in half to get the
solution to a problem on numerical approximations.

Suppose 𝑓 is a continuous function defined on the interval [𝑎, 𝑏] with 𝑓(𝑎) and 𝑓(𝑏)
having an opposite sign. This procedure will work when there is more than one root in the
interval (𝑎, 𝑏), we then assume that the root in the interval is unique.

Since the Bisection Method is based on the Intermediate Value Theorem, recall that it
implies a number 𝑝 exists in (𝑎, 𝑏) with 𝑓(𝑝) = 0. Therefore, the method is having to be
repeatedly bisecting in half of subintervals of [𝑎, 𝑏] and after each step, it will locate the
half of two points containing 𝑝.

[1]
Figure 1 shows an illustration of The Bisection Method

To begin, set 𝑎1 = 𝑎 and 𝑏1 = 𝑏 and let 𝑝1 be the midpoint of [𝑎, 𝑏]:

𝑏1 −𝑎1 𝑎1 +𝑏1
𝑝1 = 𝑎1 + 2
= 2

1
Numerical Analysis Computing Program Report

After that, consider the two conditions:


- If 𝑓(𝑝1 ) = 0, then 𝑝 = 𝑝1 , and the process is done.
- If 𝑓(𝑝1 ) ≠ 0, then 𝑓(𝑝1 ) has the same sign as either 𝑓(𝑎1 ) or 𝑓(𝑏1 ), such
as:
→ If 𝑓(𝑝1 ) and 𝑓(𝑎1 ) have the same sign, then set 𝑎2 = 𝑝1 and 𝑏2 =
𝑏1
→ If 𝑓(𝑝1 ) and 𝑓(𝑎1 ) have opposite signs, set 𝑎2 = 𝑎1 and 𝑏2 = 𝑝1 .

Then reapply the process to the interval [𝑎2 , 𝑏2 ] … … … [𝑎𝑛 , 𝑏𝑛 ], until the
approximation of the root has been reached.

Though, there are also drawbacks when using the Bisection Method, since there is a high
chance that the sequences {𝑝𝑛 }∞
𝑛=0 have the differences of 𝑝𝑛 − 𝑝𝑛−1 tend to converge to
zero while the sequence itself diverges. Inequality is the best way to stop the criterion to
apply because it comes closest to testing the relative error, as shown below:

|𝑝𝑁 −𝑝𝑁−1 |
|𝑝𝑁 |
< 𝜖, when 𝑝𝑁 ≠ 0

Nonetheless, the method has an important property that it will always converge into a
solution, and it is often used on other effective methods to approximate the root of the
solution.

Since the number of sequences is undetermined, it is handful to calculate the number of


iterations necessary by following steps:

Suppose that 𝑓 = 𝐶[𝑎, 𝑏] and 𝑓(𝑎) ∙ 𝑓(𝑏) < 0. The Bisection Method generates a
sequence of {𝑝𝑛 }∞
𝑛=1 approximating a zero 𝑝 of 𝑓 with,

𝑏−𝑎
|𝑝𝑛 − 𝑝| ≤ , when 𝑛 ≥ 1
2𝑛

II. PROGRAMING CODE FOR THE BISECTION METHOD

Code for Matlab:

a = input (‘Enter function with right hand side zero:’, ‘s’);


f = inline (a);

xl = input (‘Enter the first value of guess interval:’);


xu = input (‘Enter the end value of guess interval:’);
tol = input (‘Enter the allowed error:’);
if f(xu)*f(xl) < 0
else
fprintf (‘The guess is incorrect! Enter new guesses\n’);
xl = input (‘Enter the first value of guess interval:\n’);

2
Numerical Analysis Computing Program Report

xu = input (‘Enter the end value of guess interval:\n’);


end

for i = 2:1000
xr = (xu+xl)/2;

if f(xu)*f(xr) < 0
xl = xr;
else
xu = xr;
end

if f(xl)*f(xr) < 0
xu = xr;
else
xl = xr;
end

xnew (1) = 0;
xnew (i) = xr;
if abs((xnew(i)-xnew(i-1))/xnew(i)) <tol,break,end
end

str = ['The required root of the equation is: ', num2str(xr),


'']
t = ['The number of iterations are: ',num2str(i-1), '']

III. EXAMPLE

Excerpted from Question 4a, Exercise 2.1 in “Numerical Analysis (9th Edition)” [2]: Given
function 𝑓(𝑥) = 𝑥 4 − 2𝑥 3 − 4𝑥 2 + 4𝑥 + 4 = 0 within the interval [−2, −1] approximately
accurate within 10−2.

a.) Solution with Manual Calculations:


(𝒂 + 𝒃)
n a b 𝒑𝒏 =
𝟐
|𝒑(𝒏) − 𝒑(𝒏 − 𝟏)| 𝒇(𝒑𝒏 ) 𝒇(𝒂𝒏 ) 𝒇(𝒃𝒏 )
1 −2 −1 −1.5 0.8125 12 −1
2 −1.5 −1 −1.25 0.25 −0.90234375 0.8125 −1
3 −1.5 −1.25 −1.375 0.125 −0.288818359 0.8125 −0.90234
4 −1.5 −1.375 −1.4375 0.0625 0.195327759 0.8125 −0.28882
5 −1.4375 −1.375 −1.40625 0.03125 −0.062666893 0.195328 −0.28882
6 −1.4375 −1.40625 −1.42188 0.015625 0.062262595 0.195328 −0.06267
7 −1.421875 −1.40625 −𝟏. 𝟒𝟏𝟒𝟎𝟔 𝟎. 𝟎𝟎𝟕𝟖𝟏𝟑 −0.001208123 0.062263 −0.06267

3
Numerical Analysis Computing Program Report

→ The process stops after 7 iterations, since the error is 𝟕. 𝟖𝟏𝟑 × 𝟏𝟎−𝟐 , and the solution
𝒑𝟕 is -1.41406.

Calculations of one 𝑝𝑛 , 𝑓(𝑝𝑛 ), 𝑓(𝑎𝑛 ), and 𝑓(𝑏𝑛 ):


𝑎1 + 𝑏1
∴ 𝑝1 =
2
(−2)+(−1)
= 2
= −1.5

∴ 𝑓(𝑝1 ) = 𝑥 4 − 2𝑥 3 − 4𝑥 2 + 4𝑥 + 4
= (−1.5)4 − 2(−1.5)3 − 4(−1.5)2 + 4(−1.5) + 4
= 0.8125

∴ 𝑓(𝑎1 ) = 𝑥 4 − 2𝑥 3 − 4𝑥 2 + 4𝑥 + 4
= (−2)4 − 2(−2)3 − 4(−2)2 + 4(−2) + 4
= 12

∴ 𝑓(𝑏1 ) = 𝑥 4 − 2𝑥 3 − 4𝑥 2 + 4𝑥 + 4
= (−1)4 − 2(−1)3 − 4(−1)2 + 4(−1) + 4
= −1

b.) Solution with Matlab:

4
Numerical Analysis Computing Program Report

Method #2 of Finding the Root of One Variable Solution:


The Fixed – Point Iteration
(Contribution by: Lê Phương Nguyên and Hà Khánh Duy)

I. THEOREM

Let 𝑔 ∈ 𝐶[𝑎, 𝑏] be such that 𝑔(𝑥) ∈ [𝑎, 𝑏] for all 𝑥 in [𝑎, 𝑏]. Suppose, in addition, that 𝑔′
exists on (𝑎, 𝑏) and that a constant 0 < 𝑘 < 1 exists with:

|𝑔′(𝑥)| ≤ 𝑘, for all 𝑥 ∈ (𝑎, 𝑏)

Then, for any number 𝑝0 in [𝑎, 𝑏], the sequence defined by:

𝑝𝑛 = 𝑔(𝑝𝑛−1 ), 𝑛 ≥ 1,

converges to the unique fixed point 𝑝 in [𝑎, 𝑏].

This is a popular method to find the approximate root 𝑝0 of an equation within the interval
[𝑎, 𝑏]. The number of iterations for this method depends on the value 𝑘. If 𝑘 is near 0, the
number of iterations is small. However, if 𝑘 is near 1, the number of iterations is larger.

Figure 2 shows an illustration of The Fixed - Point Iteration [3]

II. PROGRAMING CODE FOR FIXED – POINT ITERATION

Code for Matlab:

clc
a = input('Enter function g(x) to solve x=g(x): ','s');
g = inline(a);
q = input("Enter constant k which satisfy |g'(x)|<=k: ");
x0 = input('Enter initial value: ') ;

5
Numerical Analysis Computing Program Report

tol = input('Enter the allowed error: ');

xu = 0;
t = 0;
for i = 1:1000
xr = g(x0);
err = q/(1-q)*abs(xr-x0);
if err > tol
x0 = xr; i = i+1;
else xu = xr; t = i; break,end
end

digitsOld = digits(10);
result = vpa(xu)
Iterations = t

III. EXAMPLE

Excerpted from Example 2.9 in “Phương Pháp Tính” [4]: Use fixed - point iteration method
3
to determine a solution accurate within 10−10 for 𝑥 = 𝑔(𝑥) = √1000 − 𝑥, for 𝑥 on [9,10].
Use x0=10.

a.) Solution with Manual Calculations:


1
∀𝑥 ∈ [9,10], |𝑔′ (𝑥)| ≤ 3
3√9902
= 3.3557424*10-3 = 𝑘 < 1

We will be constructing the loop 𝑥𝑛+1 = 3√1000 − 𝑥𝑛 , ∀𝑛 = 0,1,2, … … … , 𝑛. We have the


formula to find the error of the approximate root 𝑥𝑛 which is,
𝑘
|𝑥𝑛 − 𝑥𝑡𝑟𝑢𝑒 𝑟𝑜𝑜𝑡 | = ∙ |𝑥𝑛 − 𝑥𝑛−1 | = ∆𝑥𝑛
1−𝑘
We have the following table:

𝒏 𝒙𝒏 ∆𝒙𝒏
0 10
1 9.966554934 0.1127 × 10−3
2 9.966667166 0.3779 × 10−6
3 9.966666789 0.1270 × 10−8
4 9.966666791 0.6735 × 10−11

→ Thus, we get 9.966666791 after 4 iterations.

6
Numerical Analysis Computing Program Report

b.) Solution with Matlab:

7
Numerical Analysis Computing Program Report

Method #3 of Finding the Root of One Variable Solution:


Newton’s Method
(Contribution by: Vũ Anh Khoa and Lê Hồng Phúc)

I. THEOREM

Let 𝑓 ∈ 𝐶 2 [𝑎, 𝑏].

If 𝑝 ∈ (𝑎, 𝑏) is such that 𝑓(𝑝) = 0 and 𝑓0 (𝑝)6 = 0, then there exists a 𝛿 > 0 such that
Newton’s Method generates a sequence {𝑝𝑛 }∞ 𝑛=1 converging to 𝑝 for any initial
approximation 𝑝0 ∈ [𝑝 − 𝛿, 𝑝 + 𝛿].

Figure 3 shows an illustration of Newton's Method [5]

We have the equation:

𝑦 − 𝑓(𝑥𝑛 − 1) = 𝑓′(𝑥𝑛 − 1) ∙ (𝑥 − 𝑥𝑛−1 )

So let 𝑦 = 0, and 𝑥 = 𝑥𝑛 , then we have the equation to find 𝑥𝑛 :

𝑓(𝑥𝑛−1 )
𝑥𝑛 = 𝑥𝑛−1 − , ∀𝑛 = 1,2,3, … , 𝑛
𝑓 ′ (𝑥𝑛−1 )

8
Numerical Analysis Computing Program Report

II. PROGRAMING CODE FOR NEWTON’S METHOD

Code for Matlab:

clc

syms x
a = input('Enter function g(x) to solve x=g(x): ','s');
f(x) = str2sym(a);
d(x) = diff(f(x));
x0 = input('Enter initial value: ') ;
tol = input('Enter the allowed error: ');

xu = 0;
t = 0;
for i = 1:1000
xr = x0-f(x0)/d(x0);
err = abs(xr-x0);
if err > tol
x0 = xr; i = i+1;
else xu = xr; t = i; break,end
end

digitsOld = digits(10);
result = vpa(xu)
Iterations = t

III. EXAMPLE

Excerpted from Example 1 in “Brilliant.org: Newton Raphson Method” [6]: Find the root of
the equation 𝑥 2 − 4𝑥 − 7 = 0 near 𝑥 = 5 to the nearest 10−3.

a.) Solution with Manual Calculations:


We have our 𝑥0 = 5. In order to use Newton’s Method, we also need to know the derivative
of 𝑓. In this case:
∴ 𝑓(𝑥) = 𝑥 2 − 4𝑥 − 7
∴ 𝑓 ′ (𝑥) = 2𝑥 − 4

9
Numerical Analysis Computing Program Report

Using Newton’s Method, we get the following sequence of approximations:

𝒏 𝒙𝒏 𝒇(𝒙𝒏 ) 𝒇′(𝒙𝒏 )
0 5 -2 6
1 16⁄ 𝑜𝑟 5.33333 0.111111111 6.666666667
3
319⁄
2 60 2.7778 × 10−4 6.633333333
𝑜𝑟 5.31667
3 5.316624791 1.7535 × 10−9 6.633249582

→ The process stops after 3 iterations after getting 5.317, because the thousandth
and ten-thousandth of 𝑥2 and 𝑥3 are the same.

Calculations of one 𝑓(𝑥𝑛 ), 𝑓′(𝑥𝑛 ) and 𝑥𝑛 :


∴ 𝑓(𝑥0 ) = 𝑥 2 − 4𝑥 − 7
= (5)2 − 4(5) − 7
= −2

∴ 𝑓′(𝑥0 ) = 2𝑥 − 4
= 2(5) − 4
=6

𝑓(𝑥𝑛−1 ) 𝑥 2 − 4𝑥 − 7
∴ 𝑥1 = =
𝑓′(𝑥𝑛−1 ) 2𝑥 − 4
(5)2 −4(5)−7
= 2(5)−4
16
= 3
𝑜𝑟 5.33333

b.) Solution with Matlab:

10
References

[1]: Burden, R. L., Faires, J. D., & Burden, A. M. (2016). Chapter 2: Solutions of Equations in
One Variable. In Numerical Analysis (10th Edition, p. 49). Cengage Learning.

[2]: Burden, R. L., Faires, J. D., & Burden, A. M. (2010). Chapter 2: Solutions of Equations in
One Variable. In Numerical Analysis (9th Edition, p. 54). Cengage Learning.

[3]: Burden, R. L., Faires, J. D., & Burden, A. M. (2016). Chapter 2: Solutions of Equations in
One Variable. In Numerical Analysis (10th Edition, p. 59). Cengage Learning.

[4]: Lê, T. T. (2019). Chương 2. In Phương Pháp Tính (p. 22). VNU-HCMC.

[5]: Burden, R. L., Faires, J. D., & Burden, A. M. (2016). Chapter 2: Solutions of Equations in
One Variable. In Numerical Analysis (10th Edition, p. 67). Cengage Learning.
10
[6]: Newton Raphson Method. Brilliant.orf. Retrieved May1, 2021, from
https://brilliant.org/wiki/newton-raphson-method/

11

You might also like