Numerical Methods Overview and Applications
Numerical Methods Overview and Applications
Contents
1 Introduction 2
3 MATLAB 5
3.1 Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.2 Mathematical operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.3 Vectors and Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.3.1 Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.3.2 Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.3.3 Matrix operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.4 The colon (:) operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.5 Visualization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.6 Some functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
6 Gauss elimination 19
6.1 Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
6.2 General steps of Gauss Elimination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
6.3 Naive Gauss Elimination . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
6.4 Gauss elimination : Pivoting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
7 Iterative methods 26
7.1 Gauss - Seidel method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
7.2 Jacobi method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
7.3 Improvement of convergence using relaxation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
1
1 Introduction
Part in test: Theory (7 MCQs, 4 points. Include: motivation; roles, applications, formulae and insights of different
types of numerical methods
Examples of applications:
• Solving polynomial equations: Simple linear or quadratic equations, for example: x − 3 = 0 and x2 − 2x −
3 = 0, can be solved analytically. But as the degree increases, usually for degree higher than 5, analytical
solutions become impossible. → Numerical methods: Newton-Raphson, bisection methods to find the roots
approximately.
• Fluid flow - Navier-Stokes Equations: Navier–Stokes momentum equation (conservative form):
∂u 1 1
+ u · ∇u = − ∇p + ν∇2 u + ν∇(∇ · u) + g
∂t ρ 3
This partial differential equations (PDEs) describes how fluid velocity evolves. They are too complex to solve
analytically. → Numerical methods: CDF - Computational Fluid Dynamics, techniques like finite volume
or finite difference methods to discretize and solve flow fields in space and time.
• Heat Transfer - Fourier’s Law: Steady state equation:
⃗q = −k∇T
Fourier’s law models heat conduction. Analytical methods fail in complex geometries or with nonuniform materi-
als. → Numerical methods: finite difference or finite element methods to simulate temperature distributions
in systems.
• Structural and mechanical engineering: To predict mechanical response of structures, we can apply New-
ton’s 2nd law: X
F⃗ = m⃗a
Since real-world mechanical systems, turbines, or machines are very complex, analytical methods are insufficient.
→ Numerical methods: finite element analysis (FEA) to evaluate stress, strain, and deformation in complex
geometries under various loading conditions.
Note: Various applications are presented in the slides and you should definitely read them thoroughly.
2
2 Errors and uncertainty (Lecture 1)
2.1 Approximations and Round-Off errors
• Numerical methods will always give errors since the solutions are approximated. These are approximation
and round-off errors.
• In cases that we can use analytical method, we can compute the exact value of error of numerical method.
Otherwise, we would calculate estimates of the errors.
The concept is illustrated in Figure 1, with the center of the circles represent true value. (true solution)
3
Figure 1: Accuracy and Precision
In Figure 1, (a) is inaccurate and imprecise, (b) is accurate but has low precision (high uncertainty), (c) is inaccurate
but precise and (d) is accurate and precise.
• Truncation errors: happen when simplifying mathematical processes to make computations more manageable.
• Round-off errors: happen when numbers having limited significant figures.
For both type, we have the following relationship:
But using just the absolute error ignores the size of the quantity being measured. For instance, a 1 cm error is more
serious when measuring a small object (like a rivet) than a large one (like a bridge). To address this, we use the true
fractional relative error:
true error
True fractional relative error =
true value
Since the true error is defined as:
4
where εt represents the true percent relative error.
εt is for analytical solutions, for numerical approximation, we have:
approximation error
εa = × 100%
approximation
curent approximation − previous approximation
=⇒ εa = × 100%
current approximation
Another quantity that we have to consider is εs , the pre-specified percent tolerance, which is the limit of the error of
our computation. That means, our computation will be repeated until:
|εa | < εs
3 MATLAB
3.1 Variables
To assign a (new) variable, simply put:
>> x = 5.71;
If you type without the semicolon (;) the output will be printed immediately in the Command Window after Enter.
So to view variable content, simply type the variable and Enter. You can also see all the variables you are working
with in the Workspace Window.
If you do not explicitly create a variable, the result will be assigned to the default variable named ans, for example:
>> sin(1)
ans =
0.8415
5
Operator Description Example Result
^ Exponentiation 2^3 8
- Negation -5 -5
*, / Multiplication and Division 6/2 3
\ Left Division 2\6 3
+, - Addition and Subtraction 3+4 7
== Equal to 2==3 0
=
~ Not equal to 2~=3 1
> Greater than 6>2 1
< Less than 6<2 0
>= Greater than or equal to 3>=4 0
<= Less than or equal to 3<=4 1
& AND A&B 1 (true) only where both matrices contain nonzero values.
| OR A|B 1 (true) where either matrix contains a nonzero value.
~ NOT ~A 1 (true) where A is zero and 0 (false) where A is nonzero.
>> a = [1 2 3 4 5];
>> a = 1:5
The 2nd way, using ′ is transpose of a vector. In particular, we transposed a row vector to create a column vector.
6
3.3.2 Matrix
To create a matrix of 3 rows and 3 columns, we type each row then separate the rows by the semicolon ; as the
following:
>> A = [1 2 3; 4 5 6; 7 8 9];
Special matrices: matrices of all zeros or ones. You type the dimension of the matrix inside the bracket in the order
(# of row, # of column)
To access an element of a matrix, use round bracket and the position of the element in the order (row index, column index)
For example, to access the element in the first row and 2nd column:
>> A = [1 2 3; 4 5 6; 7 8 9];
>> A(1,2)
ans=
2
>> A = [3 2 1; 5 1 0; 2 1 7];
>> A’
ans=
3 5 2
2 1 1
1 0 7
B*A - Multiplication
>> B = [1 3 1; 4 9 5; 2 7 2];
>> B*A
ans=
20 6 8
67 22 39
45 13 16
B.*A - Multiplication by each element (With the . you can perform the following operation on each element of the
matrix)
>> B.*A
7
ans=
3 6 1
20 9 0
4 7 14
>> B/A
ans=
2.0652 -0.9783 -0.1522
5.9130 -2.6957 -0.1304
4.8913 -2.3696 -0.4130
We also have B./A - Matrix division by elements. (B./A ̸= A./B just like B/A ̸= A/B)
>> [B A]
ans =
1 3 1 3 2 1
4 9 5 5 1 0
2 7 2 2 1 7
>> [B; A]
ans =
1 3 1
4 9 5
2 7 2
3 2 1
5 1 0
2 1 7
>> x = 1:10
x=
1 2 3 4 5 6 7 8 9 10
>> x = 1:2:10
x=
1 3 5 7 9
8
We can also create a decreasing vector with step like this:
>> x = 10:-2:0
x=
10 8 6 4 2 0
>> A = [1 2 3; 4 5 6; 7 8 9];
>> A(:,2) % extract elements in every row & in 2nd column
ans=
2
5
8
>> A = [1 2 3; 4 5 6; 7 8 9];
>> A(1,:) % extract elements in the 1st row & all column
ans=
1 2 3
• A(:) - Extract all elements of matrix A: (note that the result has dimension 6 × 1)
>> A = [1 2 3; 4 5 6];
>> A(:) % extract all elements
ans=
1
2
3
4
5
6
• A(n, j:k) - Extract elements in nth row and from column jth to kth:
>> A = [4 5 6; 7 8 9];
>> A(1, 2:3) % 1st row, column 2 to 3
ans=
5 6
9
• A(:) - Extract all elements of A and put the result in form of a column: (the matrix is read by column)
>> A = [4 5 6; 7 8 9];
>> A(:) % all elements
ans=
4
7
5
8
6
9
One solution:
3.5 Visualization
The 4 basic lines to make a plot in MATLAB:
>> figure
>> x = 1:10;
>> y = 2*x + 1;
>> plot(x, y)
Note that for the plot() function, we specify x and y. Style of the plot (type of plot, color, etc.) can be also be
added. More details: Link.
To make titles and labels for x and y-axis:
10
title(’2-D Line Plot’)
xlabel(’x’)
ylabel(’cos(5x)’)
>> x = 0:pi/10:2*pi;
>> y1 = sin(x);
>> y2 = sin(x-0.25);
>> y3 = sin(x-0.5);
>> figure
>> plot(x,y1,’g’,x,y2,’b--o’,x,y3,’c*’)
Figure 2: Result.
a = [1 2 3 4 5];
s = sum(a);
% s = 15
syms x;
expr = x^2 + 3*x + 2;
syms k;
s = symsum(1/k^2, k, 1, Inf);
11
diag: Creates a diagonal matrix or extracts the diagonal of a square matrix.
A = diag([1 2 3])
A=
1 0 0
0 2 0
0 0 3
diag(A)
ans=
1
2
3
linspace: Generates a linearly spaced vector. Example: create a vector from 0 to 1, have 5 elements equally spaced
(step = (1-0)/5 = 0.25)
x = linspace(0, 1, 5)
x=
0 0.25 0.5 0.75 1
f zero: Finds a root of a nonlinear function. (note: different initial points may give different results)
root=
2
root=
-2
syms x;
sol = solve(x^2 - 4 == 0, x)
sol=
-2
2
sin: Computes sine of input in radians. (similar for cos, tan, cot)
sin(pi/2)
12
ans=
1
f or loop:
Example (from Labwork): Write a script to calculate: 12 + 22 + ... + 10002
result = 0;
for i = 1:1000
result = result + i^2;
end
fprintf(’Result: %d’, result)
Result: 333833500
while loop:
Example (from Labwork): Write code with while loop that makes the computer count only the odd number from 1 to
N (N: integer), for example from 1 to 5, there are 3 odd number.
N = 5;
i = 1;
odd_count = 0;
while i <= N
if mod(i, 2) == 1
odd_count = odd_count + 1;
end
i = i + 1;
end
fprintf(’Count of odd numbers from 1 to %d: %d.’, N, odd_count)
13
Prerequisite: consider the function on an interval [a; b] given that f (a)f (b) < 0. This guarantees that the function =
0 at some point.
Steps:
1. Calculate the midpoint of the interval: c = 0.5 ∗ (a + b)
2. Calculate f (c)
3. Check if |f (c)| < ε or |b − a| < ε, stop and return c as the root. (ε is a prespecified stopping criterion)
4. Examine the sign of f(c) and change the interval to [a, c] or [c, b] if f (a)f (c) < 0 or f (c)f (b) < 0. Back to step 1.
• xnew
r : the root for the present iteration
• xold
r : the root from the previous iteration
Limitations
Limitations of Bisection method:
• The bisection method only finds roots where the function crosses the x axis. It cannot find roots where the
function is tangent to the x axis.
There would be no sign change in this case.
Example
Find the root of f (x) = x3 − x − 2
Choose a and b that f (a)f (b) < 0: a = 1, b = 2.
Set stopping criterion: relative error εs = 5% = 0.05
Solution:
Step 1: Compute midpoint.
The midpoint is:
1+2
xr = = 1.5
2
Step 2 : Evaluate function
1.5 − 1 0.5
|εa | = × 100 = × 100 ≈ 33.33%
1.5 1.5
14
εa > εs =⇒ continue
a = 1.5, b=2
εa > εs =⇒ continue
Update interval:
f (1.5) = −0.125
f (1.75) = 1.609375
f (2) = 4
=⇒ new interval: [1.5, 1.75]
Continue with another iteration, until εa <= εs
From iteration 3, we have a table
Iteration a b c εa
1 1 2 1.5 100%
2 1.5 2 1.75 14.29%
3 1.5 1.75 1.625 7.69%
4 1.5 1.625 1.5625 4%
15
Figure 4: Illustration of Newton-Raphson method.
Steps:
1. Evaluate the derivative f ′ (x) symbolically.
2. Have an initial guess xi , estimate the new value xi+1 by the Newton-Raphson formula:
f (xi )
xi+1 = xi −
f ′ (xi )
Limitations
• This algorithm can have slow convergence due to the nature of the function or a poor first initial guess.
• Newton-Raphson can oscillate around a local maximum or local minimum, as near-zero slope is reached in this
case. In general, this algorithm has problems with near-zero slopes, sometimes, it can point us to a really far
away region from the real root. Look at Figure 5, notice the sequence of x1 , x2 , ...
Quoted from textbook: “Thus, there is no general convergence criterion for Newton-Raphson. Its convergence
depends on the nature of the function and on the accuracy of the initial guess. The only remedy is to have an initial
guess that is “sufficiently” close to the root. And for some functions, no guess will work! Good guesses are usually
predicated on knowledge of the physical problem setting or on devices such as graphs that provide insight into the
behavior of the solution. The lack of a general convergence criterion also suggests that good computer software should
be designed to recognize slow convergence or divergence.”
16
Figure 5: Illustration of problems with Newton Raphson Method
Example
Example: Estimate the root of f (x) = e−x − x, employing an initial guess of x0 = 0.
Solution:
f ′ (x) = −e−x − 1
Step 2: Estimate xi+1
f (xi ) e−xi − xi
xi+1 = xi − = x i −
f ′ (xi ) −e−xi − 1
For the first iteration, x0 = 0 and:
e−0 − 0
x1 = 0 − = 0.5
−e−0 − 1
Step 3: Estimate the relative error:
0.5 − 0
|εa | = × 100% = 100%
0.5
|εa | > εs =⇒ End of iteration 1, start iteration 2.
Iteration 2:
e−0.5 − 0.5
x2 = 0.5 − = 0.5663
−e−0.5 − 1
0.5663 − 0.5
|εa | = × 100% = 11.7%
0.5663
|εa | > εs =⇒ End of iteration 2, start iteration 3.
Continue until |εa | < εs . It should take 1 more iteration. (Check this yourself, i might be wrong.) We have a table of
all iterations:
i xi εa
1 0.5 100%
2 0.5663 11.7%
3 0.5671 0.15%
We can see that |εa | <= εs =⇒ iterations end
• Recall that the Newton-Raphson method was predicated on employing the derivative (that is, the slope) of a
function to estimate its intercept with the axis of the independent variable—that is, the root.
• This estimate based on a first - order Taylor series expansion :
17
– xi : the initial guess
– xi+1 : the point where the slope intercepts the x axis → f (xi+1 ) = 0 → we have the single - equation form
of the Newton - Raphson method :
f (xi )
xi+1 = xi − ′
f (xi )
→ The multi - equation form is derived in an identical fashion. However, a multivariable Taylor series must be
used.
Suppose that we have a systems of 2 nonlinear equations, with 2 unknown variable x, y :
(
u(x, y) = 0
v(x, y) = 0
ui ∂v ∂ui
∂y − vi ∂y
i
vi ∂u
∂x
i
− ui ∂v
∂x
i
The dominator of each of these equations is the determinant of Jacobian of the system.
Solution : First, we compute the partial derivatives and evaluate them at the initial guesses of x and y :
∂u0 ∂u0
= 2x + y = 2(1.5) + 3.5 = 6.5 = x = 1.5
∂x ∂y
∂v0 ∂v0
= 3y 2 = 3(3.5)2 = 36.75 = 1 + 6xy = 1 + 6(1.5)(3.5) = 32.5
∂x ∂y
Thus, the determinant of the Jacobian for the first iteration is
6.5(32.5) − 1.5(36.75) = 156.125
The values of the functions can be evaluated at the initial guesses as :
u0 = (1.5)2 + 1.5(3.5) − 10 = −2.5
v0 = 3.5 + 3(1.5)(3.5)2 − 57 = 1.625
18
These values can be substituted into Newton - Raphson method for mutiple - equation to give :
−2.5(32.5) − 1.625(1.5)
x = 1.5 − = 2.03603
156.125
1.625(6.5) − (−2.5)(36.75)
y = 3.5 − = 2.84388
156.125
Thus, the results are converging to the true values of x = 2 and y = 3. The computation can be repeated until an
acceptable accuracy is obtained.
Example 2 : Use the multiple-equation Newton-Raphson method to determine the roots of equations by using 3
iterations with initial guess : x = 0.8, y = 1.8. Round to 5 decimal places.
(
x−y+1=0
x2 + y 2 − 4 = 0
Iteration 1 :
First, we have to calculate the values of partial derivatives at those initial guess
∂u0 ∂u0
=1 = −1
∂x ∂y
∂v0 ∂v0
= 2x = 1.6 = 2y = 3.6
∂x ∂y
Then, we compute the determinant of the Jacobian :
u0 = 0.8 − 1.8 + 1 = 0
v0 = 0.82 + 1.82 − 4 = −0.12
0(1) − (−0.12)(−1)
x = 0.8 − = 0.82308
5.2
(−0.12)(1) − (0)(1.6)
y = 1.8 − = 1.82308
5.2
6 Gauss elimination
6.1 Matrix
In this part, I will introduce some matrix notations, special types of matrix, and how to represent linear algebraic
equations in matrix form.
19
• [A] : a shorthand notation for m by n matrix.
• aij an individual element of the matrix.
• a11 , a22 , a33 : the principal or main diagonal of the matrix.
• aij = aji : symmetric matrix.
• m = n : square matrices.
• Diagonal matrix
a11 0 0
[A] = 0 a22 0
0 0 a33
• Identity matrix
1 0 0
[I] = 0 1 0
0 0 1
• Banded matrix
a11 a12 0 0
a21 a22 a23 0
[A] =
0
a32 a33 a34
0 0 a43 a44
20
• A 3 × 3 set of linear equations:
a11 x1 + a12 x2 + a13 x3 = b1
a21 x1 + a22 x2 + a23 x3 = b2
a31 x1 + a32 x2 + a33 x3 = b3
• Solution:
{x} = [A]−1 {b}
21
– From the last equation, we can find xn
– Substitute to (n − 1)th equation → find xn−1
– Continue until we find all the unknowns.
Example 1 : Solve the following system of linear equations by using Naive Gauss elimination
4x1 + x2 − x3 = 3
2x1 + 7x2 + x3 = 19
x1 + −3x2 + 12x3 = 31
Solution :
Step 1 :
First, we transfer the system to a coefficient matrix :
4 1 −1 3
[A] = 2 7 1 19
1 −3 12 31
Then, we apply the Naive Gauss elimination step by step :
→ x3 = 3
Step 3 : Back-substituted.
Substitute back x3 = 3 to the remaining equations :
4x1 + x2 = 6
x 1 = 1
6.5x2 = 13 → x2 = 2
13x3 = 39 x3 = 3
Answer : x1 = 14 x2 = −32 x3 = −5
22
6.4 Gauss elimination : Pivoting
• The reason why naive Gauss elimination is called ”naive” because during 2 main steps, division by zero can
occur. For example :
2x2 + 3x3 = 8
4x1 + 6x2 + 7x3 = −3
2x1 − 3x2 + 6x3 = 5
The first coefficient of the first equation is 0, so we cannot use it to turn other coefficients to 0 → method failed.
• In the process of calculation, you may have round off error when you divide by a number that is approximately
0.
• Determine the coefficient with the largest absolute value in the column below the pivot element
• The rows can then be switched so that the largest element is the pivot element. This is called partial pivoting
We can see that first element is 0, and the largest element is 3 at the last row → we need to exchange row 1 and row
3:
L3 ←→ L1
The matrix [A] become
3 1 0 2
[A] = 2 1 1 1
0 2 5 1
Step 3 : Now we use row operations as naive Gauss elimination
−2
L2 + L1 → L2
3
L3 + −6L2 → L3
A become upper triangular form :
3 1 0 2
1 −1
[A] = 0 3 1.5 3
0 0 −1 3
Step 4 : The corresponding system of linear equations will be
3x1 + x2 = 2
1 −1
x2 + x3 =
3 3
−x3 = 3
23
→ x3 = −3
Step 5 : Substitute back x3 = −3 to the remaining equations:
3x1 + x2 = 2
x1 = −2
1 −1
x2 + −3 = → x2 = 8
3 3
x3 = −3
x3 = −3
Example 2 : Suppose that a team of three parachutists is connected by a weightless cord while free-falling at a velocity
of 5m/s. Calculate the tensions T and R in each section of cord and the acceleration a of the team (round to 4
decimal places), given the following:
24
Figure 7: Forces acting on each parachutists
Because when the parachutists are falling down, there exists air resistance, so we have drag coefficients c in the
table below :
Now we apply Newton’s Second law to each parachutist, with positive direction is downward.
• Parachutist 1 : m1 g − T − c1 v = m1 a
• Parachutist 2 : m2 g + T − c2 v − R = m2 a
• Parachutist 3 : m3 g − c3 v + R = m3 a
Substitute m, c from Table 1, g = 9.8m/s2 , v = 5m/s, we have a system of linear equations
70 · 9.8 − T − 10 · 5 = 70a 70a + T = 636
60 · 9.8 + T − 14 · 5 − R = 60a → 60a − T + R = 518
40 · 9.8 − 17 · 5 + R = 40a 40a − R = 307
The rest is up to you, use Gauss elimination Pivoting to solve this system of linear equations
Answer : x1 = 2 x2 = −3 x3 = 1
Exercise 2 : Solve
2x2 + 1x3 = 4
x1 + x2 + x3 = 6
2x1 − x2 + x3 = 5
Answer : x1 = 5 x2 = 3 x3 = −2
25
Exercise 3 : Suppose that a team of three parachutists is connected by a weightless cord while free-falling at a
velocity v = 9m/s, g = 9.8m/s2 . Calculate the tensions T and R in each section of cord and the acceleration a of
the team (round to 4 decimal places), given the following:
7 Iterative methods
7.1 Gauss - Seidel method
• The most commonly used iterative method for solving linear equations
• Employ initial guesses
• Iterates to obtain refined estimates of the solution
• Convergence can be checked using the criterion
→ round-off errors controlled by the number of iterations.
Principle
Suppose that we have a system of linear equations :
a11 x1 + a12 x2 + a13 x3 = b1
a21 x1 + a22 x2 + a23 x3 = b2
a31 x1 + a32 x2 + a33 x3 = b3
If the diagonal elements (a11 , a22 , a33 ) are all nonzero, then
• the first equation can be solved for x1
• the second for x2
• the third for x3
To be more specific :
b1 − a12 x2 − a13 x3
x1 =
a11
b2 − a21 x1 − a23 x3
x2 =
a22
b − a31 x1 − a32 x2
x 3 = 3
a33
26
where:
• (j) represents the current iteration.
• (j − 1) represents the previous iteration.
A simple approach is to assume that the initial guesses are all zero. (x01 = x02 = x03 = 0). You can use other guesses
(if prior knowledge exists), but these are usually sufficient.
As each new x value is computed, it is immediately used in the next equation to determine another x value. For
example, xj1 is used immediately to calculate xj2 .
Stopping Criterion
Convergence can be checked for each iteration using the criterion:
xji − xj−1
i
εa,i = × 100% ≤ εs
xji
Converge condition
If the following condition holds, Gauss-Seidel will converge:
n
X
|aii | > |aij |
j=1
j̸=i
Example
Use the Gauss-Seidel method to obtain the solution for
3x1 − 0.1x2 − 0.2x3 = 7.85
0.1x1 + 7x2 − 0.3x3 = −19.3
0.3x1 − 0.2x2 + 10x3 = 71.4
27
Solution
Step 1: Solve each equations for its unknown on the diagonal:
7.85 + 0.1x2 + 0.2x3
x 1 =
3
−19.3 − 0.1x1 + 0.3x3
x2 =
7
71.4 − 0.3x 1 + 0.2x2
x 3 =
10
Step 2: Assume x2 = 0 and x3 = 0, we can calculate:
28
Jacobi vs Gauss Seidel
As you can see, Jacobi method will calculate all the values of x1 , x2 , x3 in the first iteration, then use those values
for the second iteration.
This is different from the Gauss-Seidel method using a new value of x immediately to find another x value.
Example
Solve the following system of linear equations by Jacobi method :
10x1 − x2 + 2x3
=6
−x + 11x − x + 3x
= 25
1 2 3 4
2x 1 − x 2 + 10x 3 − x 4 = −11
3x2 − x3 + 8x4
= 15
Solution :
Step 1 : Solve each equations for its unknown on the diagonal:
6 − 2x3 + x2
x1 =
10
25 − 3x 4 + x3 + x1
x 2 =
11
x 3 =
−11 + x 4 + x2 − 2x1
10
x4 = 15 − 3x2 + x3
8
Step 2 : We choose x1 = x2 = x3 = x4 = 0 as intial approximation, then the solution of the first iteration are :
6−0+0
x1 = = 0.6
10
25 − 0 + 0 + 0
x 2 =
11
−11 + 0+0−0
x3 =
10
x4 = 15 − 0 + 0 = 1.875
8
Step 3 : The iteration will continue until the desired accuracy has been reached. Here are the approximated solutions
after five iterations
29
Iteration x1 x2 x3 x4
1 0.6 2.27272 -1.1 1.87500
2 1.04727 1.71590 -0.80522 0.88522
3 0.93263 2.05330 -1.0493 1.13088
4 1.01519 1.95369 -0.9681 0.97384
5 0.98899 2.0114 -1.0102 1.02135
Types of relaxation
Types I:
• If λ is between 0 and 1 → this type of modification is underrelaxation.
• It is used to make a nonconvergent system converge or to hasten convergence.
Types II :
• If λ is between 1 and 2 → this type of modification is overrelaxation.
• accelerate the convergence of an already convergent system
• It is also called as succesive or simultaneous overrelaxation.
Example
Solve the following system with Gauss Seidel using overrelaxation (λ = 1.2)
(
−3x1 + 12x2 = 9
10x1 − 2x2 = 8
Solution :
Step 1 : We rearrange the equations so that they are diagonally dominant :
(
10x1 − 2x2 = 8
−3x1 + 12x2 = 9
Step 2 : Solve the first equation for x1 , the second equation for x2 .
8 + 2x2
x 1 =
= 0.8 + 0.2x2
10
x2 = 9 + 3x1 = 0.75 + 0.25x1
12
Step 3 : First iteration : using initial guesses x1 = x2 = 0, we can solve for x1
x1 = 0.8 + 0.2(0) = 0.8
Step 4 : Before solving x2 , we first apply relaxation for x1 :
x1,r = 1.2(0.8) − 0.2(0) = 0.96
r means it is ”relaxed” value.
Step 5 : This result is then used to compute x2 :
x2 = 0.75 + 0.25(0.96) = 0.99
Step 6 : Before moving to the next iteration, we then apply relaxation for x2 :
x2,r = 1.2(0.99) − 0.2(0) = 1.188
The procedure continue until it reach the desired accuracy.
30
The stopping criteria for the bisection method involves continuing iterations until the relative approximate error εa falls below a pre-set threshold εs, typically checking the sign change at each step to ensure the root remains within the narrowed interval. In contrast, the Newton-Raphson method's stopping criteria depends on the relative absolute error between consecutive guesses, considering convergence only when this error is less than εs, which directly relates to the function's derivative near the root .
Forward elimination in Gauss Elimination involves sequentially eliminating variables via row operations to create an upper triangular matrix, whereas Gaussian pivoting addresses the potential numerical instability by rearranging rows such that the largest pivot candidate is chosen for each step. Pivoting adjusts for zero coefficients and minimizes round-off errors, enhancing stability and accuracy compared to just forward elimination .
Forward elimination in the Naive Gauss Elimination method involves transforming the coefficient matrix of a system of linear equations into an upper triangular form. This is achieved through elementary row operations, eliminating variables systematically from lower to higher equations. For example, the first variable is eliminated from the second to nth equations, the second variable from the third to nth equations, continuing until each subsequent equation has a zero below the diagonal .
The Newton-Raphson method might be inappropriate for functions with areas of near-zero slope, leading to unpredictable behavior or convergence failure. Its reliance on the initial guess's proximity to the root means it might not converge for non-linear or complex functions without prior knowledge of the function's behavior. Mitigation strategies include using graphing tools to obtain a better initial guess and incorporating additional convergence checks in software implementations to handle slow or non-converging scenarios .
The Newton-Raphson method is a root-finding algorithm that uses an initial guess close to the root, calculating subsequent estimates by drawing tangent lines to f(x) at the initial point. The method improves guesses by using the formula a' = a - f(a)/f'(a), where f'(a) is the derivative of the function. This approach iteratively refines the estimate, typically bringing it closer to the actual root with each step .
The bisection method finds the root of a polynomial function by iteratively narrowing a search interval where the function changes sign, indicating a root. The key steps involve: choosing initial points 'a' and 'b' such that f(a)f(b) < 0, calculating the midpoint 'xr = (a + b) / 2', evaluating the function at the midpoint, and updating the interval based on the sign of f(xr). This process repeats until the relative approximate error εa is less than or equal to a pre-set stopping criterion εs .
To adapt the Newton-Raphson formula for a system of two nonlinear equations, a multivariable Taylor series expansion is used. The method involves calculating the Jacobian matrix and applying it to iteratively solve the equations u(x, y) = 0 and v(x, y) = 0. This results in modifying the formula to reflect the derivatives with respect to each variable and updating both variables simultaneously at each step .
The Newton-Raphson method can face challenges such as slow convergence, especially if the function's slope is near zero or the initial guess is poor. This method can oscillate around a local maximum or minimum, leading to misleading results. The lack of a general convergence criterion means that success often depends on the quality of the initial guess. For some functions, no initial guess will ensure convergence, requiring insight into the physical problem setting to make a good guess .
Back substitution is used after transforming a system of linear equations into upper triangular form through Gauss elimination. Starting from the last equation, which contains only one variable, you solve for that variable and substitute its value into the preceding equations. This process continues back through the equations, solving for each unknown in reverse order .
Partial pivoting enhances the Gauss elimination process by preventing numerical instability and division by zero, which can occur in the Naive Gauss Elimination method. It involves selecting the pivot element with the largest absolute value in the column below the pivot position and swapping rows as needed. This reduces round-off errors and increases the method's robustness for solving linear equations .