Numerical Methods
By Benabderrezak Youcef
Semester 3 – UEM (Methodological Unit)
Credits:
4
Coefficient:
2
Prerequisites:
Evaluation:
Basic mathematics
Exam (60%) + Continuous (40%)
For Computer Science Students
With real examples from Algerian businesses:
Yassir, Jumia, Djezzy, Sonatrach, Condor Electronics
License Informatique – Licence Professionnelle
Contents
1 Introduction to Numerical Analysis
4
1.1
Why Do We Need Numerical Methods? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
1.2
Floating-Point Numbers and Rounding Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
1.2.1
How Computers Store Numbers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
4
1.2.2
Rounding Errors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5
Stability and Conditioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5
1.3
2 Direct Methods for Solving Linear Systems
7
2.1
Triangular Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7
2.2
Gauss Elimination Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
10
2.2.1
Example 1: Gauss Elimination 3×3 (Jumia Algeria) . . . . . . . . . . . . . . . . . . . . . . . . .
10
2.2.2
Example 2: Gauss Elimination 4×4 (Condor Electronics Budget) . . . . . . . . . . . . . . . . . .
11
LU Factorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
15
2.3.1
15
2.3
Example: LU Factorization 3×3 (Yassir Zones) . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3 Iterative Methods for Solving Linear Systems
18
3.1
General Ideas . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
18
3.2
Jacobi Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
18
3.2.1
Example: Jacobi Method (Sonatrach Budget) . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
18
Gauss-Seidel Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
23
3.3.1
Example: Gauss-Seidel (Same Sonatrach System) . . . . . . . . . . . . . . . . . . . . . . . . . .
23
3.4
Successive Over-Relaxation (SOR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
26
3.5
Convergence: When Do These Methods Work? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
28
3.3
4 Eigenvalues and Eigenvectors
29
4.1
4.2
What Are Eigenvalues? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
29
4.1.1
Example: Eigenvalues 2×2 (Djezzy Subscriber Growth) . . . . . . . . . . . . . . . . . . . . . . .
29
4.1.2
Gershgorin’s Circle Theorem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
31
Power Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
31
4.2.1
32
Example: Power Method (Yassir Traffic) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
5 Matrix Analysis
35
5.1
Vector Spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
35
5.2
Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
35
5.2.1
Operations on Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
35
5.2.2
Linear Maps and Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
36
5.2.3
Inverse of a Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
36
5.2.4
Trace and Determinant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
38
5.2.5
Eigenvalue Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
38
5.2.6
Similar Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
38
5.2.7
Special Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
39
Norms and Scalar Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
39
5.3.1
What is a Norm? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
39
5.3.2
Scalar Product and Vector Norms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
39
5.3.3
Matrix Norms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
40
5.3
Summary
41
1 Introduction to Numerical Analysis
1.1 Why Do We Need Numerical Methods?
Many problems in computer science are too big to solve by hand. We need the computer to find close answers (approximate,
not perfect).
Real Algerian examples:
• Jumia Algeria (online shop): 5000 products, how to set the best price for all? → big system of equations.
• Yassir (VTC app): Find the best route for 200 drivers and 300 clients in Algiers. → needs matrix math.
• Sonatrach (oil company): Split the yearly budget between 10 departments with many rules. → linear system.
You cannot solve these by hand. You need a computer + numerical methods.
1.2 Floating-Point Numbers and Rounding Errors
1.2.1 How Computers Store Numbers
Computers store numbers in floating-point format:
x = ± m × be
• m = mantissa (the digits), example: 1.2345
• b = base (usually 2 for computers)
• e = exponent (moves the decimal point)
Example: 0.004725 = 4.725 × 10−3
Jumia Example: A phone costs 45 999.99 DZD on Jumia. The computer stores it in binary:
1.01100111... × 215 ≈ 45 999.98...
This is not exactly 45 999.99 DZD! This is why online shop totals sometimes show wrong centimes.
Fix for your code: Store prices in centimes (integers): 4 599 999 instead of 45 999.99.
1.2.2 Rounding Errors
Computers have limited memory, so they must round numbers. This makes small errors.
Two types of errors:
• Absolute Error = |exact value − approximate value|
• Relative Error =
|exact − approx|
|exact|
Yassir Example: The Yassir app calculates the distance from a client in Bab Ezzouar to a driver in Hydra.
• Real distance (GPS): 8.7834 km
• App shows: 8.78 km (rounded)
• Absolute error: |8.7834 − 8.78| = 0.0034 km = 3.4 meters
• Relative error: 0.0034/8.7834 = 0.04%
For Yassir, 3.4 meters error is OK. For a surgery robot, it is NOT OK.
Sonatrach Example: Sonatrach has a 100 billion DZD budget. Split equally for 3 divisions:
100,000,000,000 ÷ 3 = 33,333,333,333.333...
Computer rounds to 33 333 333 333.33. Total = ×3 = 99 999 999 999.99.
Missing: 0.01 DZD! With 1 million transactions per day: 0.01 × 1,000,000 = 10,000 DZD lost per day!
Two ways to round:
• Truncation: Just cut extra digits. 3.14159 → 3.141
• Rounding: Look at next digit. If ≥ 5, add 1. 3.14159 → 3.142
1.3 Stability and Conditioning
Well-conditioned: Small change in input → small change in output. Good!
Ill-conditioned: Small change in input → BIG change in output. Bad!
Condition Number: cond(A) = ∥A∥ · ∥A−1 ∥
If cond(A) ≈ 1 → safe.
If cond(A) is very big → dangerous.
Djezzy Example (Ill-Conditioned): Djezzy sells 2 plans (A and B):
• Client 1 bought: 1 Plan A + 1 Plan B = 2000 DZD
• Client 2 bought: 1 Plan A + 1.001 Plan B = 2000.50 DZD
xA + xB = 2000
xA + 1.001 xB = 2000.50
Solution: xB = 500 DZD, xA = 1500 DZD.
Now change 2000.50 to 2001 (only 0.50 DZD change!):
xB = 1000,
xA = 1000
A small change (0.50 DZD) caused a big change in the answer. This system is ill-conditioned.
Stable algorithm: Small errors stay small at each step.
Unstable algorithm: Small errors grow bigger at each step.
2 Direct Methods for Solving Linear Systems
We want to solve Ax = b, where A is a matrix, x is what we look for, and b is known.
Why in Algerian CS context?
• Jumia: Find how many phones, laptops, tablets to order from 3 suppliers.
• Yassir: Calculate the best fare using distance, time, and demand in Algiers.
• Condor: Split production budget between TV, phone, and tablet departments.
2.1 Triangular Systems
An upper triangular system has zeros below the diagonal. We solve from bottom to top (back-substitution).
!
n
1
xi =
aii
bi − ∑ ai j x j
(from i = n down to 1)
j=i+1
Yassir Example – Back-Substitution: Find the price per km (x1 ), base fare (x2 ), and night bonus (x3 ) for Yassir rides
in Algiers:
2 x1 + 3 x2 + 1 x3 = 1500
4 x2 + 2 x3 = 1200
5 x3 = 500
First, write it as a matrix A x = b (and the augmented form [A | b]). Notice the zeros below the diagonal – this is
what “upper triangular” means:
2
0
0
|
3 1 x1 1500
=
4 2 x2 1200
0 5 x3
500
{z } | {z } | {z }
A
x
=⇒
2 3 1 1500
0 4 2 1200
0 0 5 500
b
The bottom row has only one unknown (5 x3 = 500), so we start there and work upward.
Step 1 (bottom): 5 x3 = 500 ⇒ x3 = 100 DZD (night bonus)
Step 2 (up): 4 x2 + 2(100) = 1200 ⇒ 4 x2 = 1000 ⇒ x2 = 250 DZD (base fare)
Step 3 (up): 2 x1 + 3(250) + 100 = 1500 ⇒ 2 x1 = 650 ⇒ x1 = 325 DZD/km
Result: Price/km = 325 DZD,
Base fare = 250 DZD,
Night bonus = 100 DZD
Interpretation: A Yassir ride of 10 km during the day costs: 250 + 325 × 10 = 3500 DZD. At night, add 100 DZD
bonus: 3500 + 100 = 3600 DZD. The base fare (250 DZD) is what you pay just to start the ride, even before the car moves.
The night bonus (100 DZD) is small, so Yassir wants to keep night prices close to day prices to attract more clients.
Python implementation – Back-substitution:
1
import numpy as np
2
3
# Solve an upper-triangular system U x = b (zeros below the diagonal)
4
def back_substitution(U, b):
5
# n = number of equations (size of the system)
6
n = len(b)
7
# x = array of zeros that will hold the solution
8
x = np.zeros(n)
9
# Loop from the LAST row (n-1) up to the first row (0)
10
for i in range(n - 1, -1, -1):
11
# Start from the right-hand side value b[i]
12
s = b[i]
13
# Subtract the already-known variables x[i+1..n-1]
14
for j in range(i + 1, n):
15
# Remove the contribution a_ij * x_j
16
s -= U[i][j] * x[j]
17
# Divide by the diagonal (pivot) to isolate x_i
18
x[i] = s / U[i][i]
19
# Return the full solution vector
20
return x
21
22
# Yassir example: 2x1+3x2+x3=1500 ; 4x2+2x3=1200 ; 5x3=500
23
U = np.array([[2, 3, 1], [0, 4, 2], [0, 0, 5]], dtype=float)
24
b = np.array([1500, 1200, 500], dtype=float)
25
# Prints [325. 250. 100.]
->
price/km, base fare, night bonus
26
print(back_substitution(U, b))
A lower triangular system has zeros above the diagonal. Solve from top to bottom (forward substitution).
2.2 Gauss Elimination Method
Idea: Change the system into upper triangular form using row operations, then use back-substitution.
Allowed operations:
1. Swap two rows
2. Multiply a row by a number (̸= 0)
3. Add a multiple of one row to another
2.2.1 Example 1: Gauss Elimination 3×3 (Jumia Algeria)
Jumia sells 3 products: Phone (x1 ), Laptop (x2 ), Tablet (x3 ). Revenue from 3 days (in thousands DZD):
Augmented matrix [A | b]:
Day 1:
2 x1
+1 x2
−1 x3
= 800
Day 2:
−3 x1
−1 x2
+2 x3
= −1100
Day 3:
−2 x1
+1 x2
+2 x3
= −300
1 −1
800
2
−3 −1 2 −1100
−300
−2 1
2
Step 1: Remove x1 from Row 2 and Row 3. Pivot = 2
R2 ← R2 + 23 R1 : [0, 0.5, 0.5, 100]
R3 ← R3 + R1 : [0, 2, 1, 500]
2 1 −1 800
0 0.5 0.5 100
0 2
1 500
Step 2: Remove x2 from Row 3. Pivot = 0.5
R3 ← R3 − 4 R2 : [0, 0, −1, 100]
2 1 −1 800
0 0.5 0.5 100
0 0 −1 100
Step 3: Back-substitution
−1 · x3 = 100
⇒
x3 = −100 (tablet: discount)
0.5 x2 + 0.5(−100) = 100
⇒
x2 = 300
2 x1 + 300 − (−100) = 800
⇒
x1 = 200
Result: Phone = 200k DZD,
Laptop = 300k DZD,
Tablet discount = 100k DZD
Interpretation: Jumia earns the most from laptops (300k DZD/day). Phones bring 200k DZD/day. The negative value
for tablets (−100k) means Jumia is losing money on tablets – maybe selling them at a discount to attract customers. This is
a common e-commerce strategy: sell tablets cheap so people come to the site, then they also buy phones and laptops (which
are profitable).
2.2.2 Example 2: Gauss Elimination 4×4 (Condor Electronics Budget)
Condor has 4 departments: R&D (x1 ), Marketing (x2 ), Production (x3 ), Sales (x4 ). Budget rules (in millions DZD):
Augmented matrix:
Rule 1:
1 x1
+2 x2
−1 x3
+1 x4
= 20
Rule 2:
2 x1
+5 x2
−1 x3
+4 x4
= 55
Rule 3:
−1 x1
+1 x2
+4 x3
+2 x4
= 35
Rule 4:
3 x1
+1 x2
−2 x3
+1 x4
= 10
1
2
−1
3
2 −1 1 20
5 −1 4 55
1 4 2 35
1 −2 1 10
Step 1: Remove x1 from Rows 2, 3, 4. Pivot = 1
R2 ← R2 − 2R1 : [0, 1, 1, 2, 15]
R3 ← R3 + R1 : [0, 3, 3, 3, 55]
R4 ← R4 − 3R1 : [0, −5, 1, −2, −50]
Step 2: Remove x2 from Rows 3, 4. Pivot = 1
R3 ← R3 − 3R2 : [0, 0, 0, −3, 10]
R4 ← R4 + 5R2 : [0, 0, 6, 8, 25]
1
0
0
0
2 −1
1
1
0
0
0
6
20
2 15
−3 10
8 25
1
Pivot is ZERO! We must swap R3 and R4 . This is called partial pivoting.
After swap:
1
0
0
0
2 −1
1
1
0
6
0
0
20
2 15
8 25
−3 10
1
Step 3: Back-substitution
−3 x4 = 10 ⇒ x4 ≈ −3.33
6 x3 + 8(−3.33) = 25 ⇒ x3 ≈ 8.61
x2 + 8.61 + 2(−3.33) = 15 ⇒ x2 ≈ 13.06
x1 + 2(13.06) − 8.61 + (−3.33) = 20 ⇒ x1 ≈ 5.83
These numbers are NOT exact – they are rounded. The true values are fractions: x4 = − 10
3 = −3.3333 . . ., x3 =
155
18 = 8.6111 . . .,
x2 = 235
18 = 13.0555 . . .,
x1 = 105
18 = 5.8333 . . . We keep 2 decimals for reading. If you plug the
rounded values back into the equations you get a small residual (a few hundredths) – that is the rounding error, not a
mistake.
Result (rounded): R&D ≈ 5.83M, Marketing ≈ 13.06M, Production ≈ 8.61M, Sales ≈ −3.33M DZD
Interpretation: Condor should give the biggest budget to Marketing (13.06M DZD) – this makes sense because Condor
needs strong advertising to compete with Samsung and Xiaomi in Algeria. Production gets 8.61M to build TVs and phones.
R&D gets the smallest positive budget (5.83M). The negative value for Sales (−3.33M) means the Sales department must
give back money – maybe their previous budget was too big, or they generated enough revenue to fund themselves. Note:
we needed partial pivoting (row swap) because pivot was zero – without this trick, the method would fail!
Python implementation – Gauss elimination with partial pivoting:
1
import numpy as np
2
3
# Solve A x = b by Gauss elimination + partial pivoting
4
def gauss(A, b):
5
# n = size of the system
6
n = len(b)
7
# Build the augmented matrix [A | b] as one float array
8
M = np.hstack([A.astype(float), b.reshape(-1, 1).astype(float)])
9
# Forward elimination: make zeros below each pivot
10
for k in range(n):
11
# Partial pivoting: find the row (>=k) with the biggest |value| in column k
12
p = np.argmax(np.abs(M[k:, k])) + k
13
# Swap the current row k with that best row (avoids dividing by ~0)
14
M[[k, p]] = M[[p, k]]
15
# Eliminate column k from every row below
16
for i in range(k + 1, n):
17
# Multiplier that makes M[i][k] become 0
18
factor = M[i][k] / M[k][k]
19
# Subtract factor * pivot-row from row i
20
M[i, k:] -= factor * M[k, k:]
21
# Back-substitution on the now upper-triangular matrix
22
x = np.zeros(n)
23
for i in range(n - 1, -1, -1):
24
# (b_i - sum of known terms) / diagonal
25
x[i] = (M[i, -1] - M[i, i+1:n] @ x[i+1:n]) / M[i][i]
26
return x
27
28
# Condor 4x4 budget system
29
A = np.array([[1,2,-1,1],[2,5,-1,4],[-1,1,4,2],[3,1,-2,1]])
30
b = np.array([20, 55, 35, 10])
31
# Prints approx [ 5.83 13.06
32
print(np.round(gauss(A, b), 2))
8.61 -3.33]
2.3 LU Factorization
Idea: Write matrix A as:
A = L ×U
L = Lower triangular (1’s on diagonal).
U = Upper triangular.
To solve Ax = b: (1) Solve Ly = b (forward).
(2) Solve Ux = y (backward).
Why LU is great: Yassir uses the same road network (matrix A) every day, but different ride requests (vector b) every
minute. With LU, you factorize once and solve many times. Much faster!
2.3.1 Example: LU Factorization 3×3 (Yassir Zones)
Yassir divides Algiers into 3 zones (Bab Ezzouar, Hydra, Cheraga). Travel matrix:
1 −1
2
A = −3 −1 2
−2 1
2
Step 1: Gauss elimination – save the multipliers
m31 = −2
2 = −1
Column 1: m21 = −3
2 = −1.5,
R2 ← R2 + 1.5 R1 = [0, 0.5, 0.5]
2
=4
Column 2: m32 = 0.5
Step 2: Build L and U
R3 ← R3 + R1 = [0, 2, 1]
R3 ← R3 − 4 R2 = [0, 0, −1]
0 0
1
L = −1.5 1 0
−1 4 1
2 1 −1
U = 0 0.5 0.5
0 0 −1
Step 3: Solve with b = [800, −1100, −300] (ride requests per zone)
Solve Ly = b (forward):
y1 = 800
− 1.5(800) + y2 = −1100 ⇒ y2 = 100
−1(800) + 4(100) + y3 = −300 ⇒ y3 = 100
Solve Ux = y (backward):
−x3 = 100 ⇒ x3 = −100
0.5 x2 − 50 = 100 ⇒ x2 = 300
2 x1 + 300 + 100 = 800 ⇒ x1 = 200
Result: Bab Ezzouar: 200 rides, Hydra: 300 rides, Cheraga: needs 100 more drivers
Interpretation: Hydra has the highest demand (300 rides) – this is expected because Hydra is a business area with
many offices. Bab Ezzouar has 200 rides (university + shopping center). The negative value for Cheraga (−100) means
there are too few drivers there – Yassir should send 100 more drivers to Cheraga. LU advantage: If tomorrow the ride
requests change (different b vector), Yassir does not redo the full calculation. They reuse L and U and only do forward +
backward substitution. This saves time when the road network (matrix A) stays the same.
Python implementation – LU factorization (Doolittle):
1
import numpy as np
2
3
# Factor A into L (lower, 1’s on diagonal) and U (upper)
4
def lu_factor(A):
5
# n = size of the square matrix
6
n = len(A)
7
# L starts as the identity matrix
8
L = np.eye(n)
9
# U starts as a copy of A (we will eliminate on it)
10
U = A.astype(float).copy()
11
# Eliminate column by column
12
for k in range(n):
13
for i in range(k + 1, n):
14
# Multiplier for row i = element below pivot / pivot
15
L[i][k] = U[i][k] / U[k][k]
16
# Subtract to create a zero in U[i][k]
17
U[i, k:] -= L[i][k] * U[k, k:]
18
19
return L, U
20
# Forward substitution: solve L y = b (L is lower triangular)
21
def forward(L, b):
22
n = len(b); y = np.zeros(n)
23
for i in range(n):
24
# y_i = b_i minus already-known terms (diagonal of L is 1)
25
y[i] = b[i] - L[i, :i] @ y[:i]
26
return y
27
28
# Back substitution: solve U x = y (U is upper triangular)
29
def backward(U, y):
30
n = len(y); x = np.zeros(n)
31
for i in range(n - 1, -1, -1):
32
33
x[i] = (y[i] - U[i, i+1:] @ x[i+1:]) / U[i][i]
return x
34
35
A = np.array([[2,1,-1],[-3,-1,2],[-2,1,2]], dtype=float)
36
b = np.array([800, -1100, -300], dtype=float)
37
L, U = lu_factor(A)
38
# Solve once factored: L y = b, then U x = y
39
x = backward(U, forward(L, b))
40
# Prints approx [200. 300. -100.]
41
print(np.round(x, 2))
3 Iterative Methods for Solving Linear Systems
3.1 General Ideas
Iterative = repeat again and again. Start with a guess x(0) , then compute x(1) , x(2) , x(3) , . . . Each step gives a better
answer. Stop when “good enough.”
Direct (Ch.2)
Iterative (Ch.3)
Answer
Exact (with rounding)
Approximate
Steps
Fixed number
Repeat until good
Best for
Small systems
Big, sparse systems
Examples
Gauss, LU
Jacobi, Gauss-Seidel
Why iterative for Algeria?
• Yassir Algiers: Road network with 50 000 intersections. Gauss is too slow! Iterative works because most
intersections connect to only 3–4 streets (sparse matrix).
• Djezzy: Network routing for 20 million subscribers uses iterative methods.
3.2 Jacobi Method
From each equation, isolate one variable. Use all old values to compute new values.
!
(k+1)
xi
=
1
aii
(k)
We use x j = old values for everything.
3.2.1 Example: Jacobi Method (Sonatrach Budget)
Sonatrach has 3 divisions. Budget rules (in billions DZD):
4 x1 + 1 x2 + 1 x3 = 600
(Exploration)
bi − ∑
j̸=i
(k)
ai j x j
1 x1 + 5 x2 + 2 x3 = 1400
(Production)
1 x1 + 2 x2 + 6 x3 = 2100
(Transport)
Isolate each variable (divide by the diagonal):
x1 = (600 − x2 − x3 )/4
x2 = (1400 − x1 − 2x3 )/5
x3 = (2100 − x1 − 2x2 )/6
Start with guess x(0) = (0, 0, 0).
Iteration 1: Use all old values (0, 0, 0):
(1)
x1 = (600 − 0 − 0)/4 = 600/4 = 150
(1)
x2 = (1400 − 0 − 0)/5 = 1400/5 = 280
(1)
x3 = (2100 − 0 − 0)/6 = 2100/6 = 350
Output after iteration 1: x(1) = (150, 280, 350)
Iteration 2: Use all old values (150, 280, 350):
(2)
x1 = (600 − 280 − 350)/4 = (−30)/4 = −7.5
(2)
x2 = (1400 − 150 − 2 × 350)/5 = (1400 − 150 − 700)/5 = 550/5 = 110
(2)
x3 = (2100 − 150 − 2 × 280)/6 = (2100 − 150 − 560)/6 = 1390/6 = 231.67
Output after iteration 2: x(2) = (−7.5, 110, 231.67)
Iteration 3: Use all old values (-7.5, 110, 231.67):
(3)
x1 = (600 − 110 − 231.67)/4 = 258.33/4 = 64.58
(3)
x2 = (1400 + 7.5 − 2 × 231.67)/5 = 944.16/5 = 188.83
(3)
x3 = (2100 + 7.5 − 2 × 110)/6 = 1887.5/6 = 314.58
Output after iteration 3: x(3) = (64.58, 188.83, 314.58)
(see the full table below)
Iter.
x1 (Exploration)
x2 (Production)
x3 (Transport)
Change ∥x(k) − x(k−1) ∥
0
0
0
0
–
1
150.00
280.00
350.00
464.6
2
−7.50
110.00
231.67
244.9
3
64.58
188.83
314.58
122.5
4
24.15
141.25
276.29
71.9
5
45.61
164.65
298.89
35.9
6
34.11
151.32
287.51
20.8
7
40.29
158.17
293.87
10.6
8
36.99
154.39
290.56
6.1
9
38.76
156.38
292.37
3.1
10
37.81
155.30
291.41
1.8
..
.
..
.
..
.
..
.
↓
∞
38.14
155.67
291.75
→0
Why is the last row the answer? (super simple)
Think of a guessing game. A friend has a secret number. You guess, and each time they say “warmer.” Your
guesses get closer and closer, until you stop changing your guess – that final guess is the secret number. Iterative
methods work the same way.
1. We start with a wrong guess (0, 0, 0). It is just a starting point – it does not need to be good.
2. Each row is a better guess. Look down the x1 column: 0 → 150 → −7.5 → 64.6 → 24.2 → . . . → 38. At first it
jumps a lot, then the jumps shrink.
3. The “Change” column tells us when to stop. It shows how much the guess moved this step: 464 → 245 →
122 → 72 → . . . → 0. Getting smaller means we are getting closer. When it reaches almost 0, the guess stopped
moving – so we cannot do better. That frozen row is our answer.
4. Why is a “frozen” guess correct? Because the frozen numbers, put back into the 3 budget equations, give
exactly 600, 1400, 2100 – the right-hand sides. In other words, they solve the system. That is the whole goal.
In one line: keep guessing until the guess stops changing, then that guess is the solution.
Result: Exploration ≈ 38.14B, Production ≈ 155.67B, Transport ≈ 291.75B DZD. This is the fixed point: plug it back
and Ax = b holds (4(38.14) + 155.67 + 291.75 ≈ 600). We take it because one more iteration no longer changes it.
Interpretation: Transport gets the biggest share (≈292B DZD = 60% of the ≈486B total). This makes sense:
Sonatrach moves oil and gas through very long pipelines across the Sahara – this is expensive. Production gets ≈156B
(32%) for extracting oil from wells at Hassi Messaoud. Exploration gets only ≈38B (8%) for finding new oil fields. The
Jacobi method found this answer after many iterations because it uses old values. Each iteration is like the company doing
one round of budget negotiation – slowly everyone agrees on the final numbers.
Note (why the numbers are “ugly”): Jacobi never gives a clean exact number in a fixed number of steps – it only gets
closer and closer. That is why we see 38.14 and not a round 38. This is normal: iterative methods trade “perfectly
exact” for “fast and close enough.” You stop once it is close enough for your needs.
Python implementation – Jacobi:
1
import numpy as np
2
3
# Solve A x = b by the Jacobi iteration
4
def jacobi(A, b, tol=1e-6, max_iter=100):
5
# n = size of the system
6
n = len(b)
7
# x = current guess, start at all zeros
8
x = np.zeros(n)
9
# Repeat at most max_iter times
10
for k in range(max_iter):
11
# x_new will hold the NEXT guess (built only from OLD x)
12
x_new = np.zeros(n)
13
for i in range(n):
14
# Sum of a_ij * x_j for every j different from i (OLD values)
15
s = sum(A[i][j] * x[j] for j in range(n) if j != i)
16
# Isolate x_i using its diagonal element
17
x_new[i] = (b[i] - s) / A[i][i]
18
# Stop if the guess barely changed (converged)
19
if np.linalg.norm(x_new - x) < tol:
20
return x_new, k + 1
21
# Otherwise adopt the new guess and loop again
22
x = x_new
23
return x, max_iter
24
25
# Sonatrach budget system (diagonally dominant -> converges)
26
A = np.array([[4,1,1],[1,5,2],[1,2,6]], dtype=float)
27
b = np.array([600, 1400, 2100], dtype=float)
28
sol, iters = jacobi(A, b)
29
# Prints approx [ 38.14 155.67 291.75] and the number of iterations used
30
print(np.round(sol, 2), "in", iters, "iterations")
3.3 Gauss-Seidel Method
Same as Jacobi, but use new values as soon as they are ready.
!
(k+1)
xi
=
1
aii
bi − ∑
(k+1)
ai j x j
−
j<i
∑
(k)
ai j x j
j>i
Uses new values already computed + old values for the rest.
3.3.1 Example: Gauss-Seidel (Same Sonatrach System)
Same equations. Start with (0, 0, 0).
Iteration 1:
(1)
x1 = (600 − 0 − 0)/4 = 600/4 = 150
(1)
x2 = (1400 − 150 − 2 × 0)/5 = 1250/5 = 250
(1)
← uses new x1 !
x3 = (2100 − 150 − 2 × 250)/6 = 1450/6 = 241.67
← uses new x1 , x2 !
Output after iteration 1: x(1) = (150, 250, 241.67)
Iteration 2:
(2)
x1 = (600 − 250 − 241.67)/4 = 108.33/4 = 27.08
(2)
x2 = (1400 − 27.08 − 2 × 241.67)/5 = 889.58/5 = 177.92
(2)
x3 = (2100 − 27.08 − 2 × 177.92)/6 = 1717.08/6 = 286.18
Output after iteration 2: x(2) = (27.08, 177.92, 286.18)
Iter.
x1 (Exploration)
x2 (Production)
x3 (Transport)
Change
0
0
0
0
–
1
150.00
250.00
241.67
372.6
2
27.08
177.92
286.18
142.4
3
33.98
158.73
291.43
20.5
4
37.46
155.94
291.78
4.5
5
38.07
155.67
291.76
0.7
6
38.14
155.67
291.75
0.07
∞
38.14
155.67
291.75
→0
Read it the same easy way: same guessing game, same stopping rule – watch the Change column shrink 372 → 142 →
20 → 4.5 → 0.7 → 0.07 until the guess freezes. Here it freezes at iteration 6 on (38.14, 155.67, 291.75), so that row is the
answer. Same final answer as Jacobi, but much faster: Jacobi needed ≈ 20 guesses, Gauss-Seidel only 6 – because it uses
each new number the moment it is ready instead of waiting.
Gauss-Seidel converges FASTER than Jacobi. Fewer iterations because it uses fresh data immediately.
Interpretation: With Jacobi, Sonatrach departments negotiate using last month’s data – slow. With Gauss-Seidel, when
Exploration fixes its budget, Production immediately uses that number to decide its own budget. This is like a real meeting:
once the boss says “Exploration gets ≈38B,” Production can instantly adjust. No need to wait for the next meeting round.
In practice, Gauss-Seidel needs about half the iterations of Jacobi for the same accuracy.
Still approximate, but faster. Compare x1 after 2 iterations: Jacobi gave −7.5 then 64.58 (wild), Gauss-Seidel gave
150 then 27.08 (already near the true ≈ 38). Same exact answer (38.14, 155.67, 291.75), but Gauss-Seidel gets there in
fewer steps because each new value is used immediately.
Python implementation – Gauss-Seidel:
1
import numpy as np
2
3
# Solve A x = b by the Gauss-Seidel iteration
4
def gauss_seidel(A, b, tol=1e-6, max_iter=100):
5
# n = size of the system
6
n = len(b)
7
# Start guess at zeros
8
x = np.zeros(n)
9
for k in range(max_iter):
10
# Keep a copy of the previous guess to measure the change
11
x_old = x.copy()
12
for i in range(n):
13
# Terms j < i use the ALREADY-UPDATED (new) x values
14
s1 = sum(A[i][j] * x[j] for j in range(i))
15
# Terms j > i still use the OLD x values
16
s2 = sum(A[i][j] * x[j] for j in range(i + 1, n))
17
# Overwrite x[i] in place -> next terms see the fresh value
18
x[i] = (b[i] - s1 - s2) / A[i][i]
19
# Stop when the update is smaller than the tolerance
20
if np.linalg.norm(x - x_old) < tol:
21
22
return x, k + 1
return x, max_iter
23
24
A = np.array([[4,1,1],[1,5,2],[1,2,6]], dtype=float)
25
b = np.array([600, 1400, 2100], dtype=float)
26
sol, iters = gauss_seidel(A, b)
27
# Prints approx [ 38.14 155.67 291.75] using fewer iterations than Jacobi
28
print(np.round(sol, 2), "in", iters, "iterations")
3.4 Successive Over-Relaxation (SOR)
Take Gauss-Seidel result and “push” it further:
(k+1)
xi
ω = relaxation factor:
(k)
= (1 − ω ) xi + ω × (Gauss-Seidel value)
ω = 1: Gauss-Seidel.
1 < ω < 2: faster.
0 < ω < 1: safer.
Yassir Example: Traffic simulation of Algiers uses SOR with ω ≈ 1.5 to compute traffic flow 3x faster than GaussSeidel.
Python implementation – SOR:
1
import numpy as np
2
3
# Solve A x = b by SOR; omega is the relaxation factor (1<omega<2 speeds up)
4
def sor(A, b, omega=1.5, tol=1e-6, max_iter=100):
5
# n = size of the system
6
n = len(b)
7
# Start guess at zeros
8
x = np.zeros(n)
9
for k in range(max_iter):
10
# Copy previous guess to check convergence later
11
x_old = x.copy()
12
for i in range(n):
13
# New (j<i) and old (j>i) neighbour contributions
14
s1 = sum(A[i][j] * x[j] for j in range(i))
15
s2 = sum(A[i][j] * x[j] for j in range(i + 1, n))
16
# Plain Gauss-Seidel value for x_i
17
gs = (b[i] - s1 - s2) / A[i][i]
18
# Blend old value and GS value: push further when omega>1
19
x[i] = (1 - omega) * x[i] + omega * gs
20
# Stop when the change is small enough
21
if np.linalg.norm(x - x_old) < tol:
22
23
return x, k + 1
return x, max_iter
24
25
A = np.array([[4,1,1],[1,5,2],[1,2,6]], dtype=float)
26
b = np.array([600, 1400, 2100], dtype=float)
27
sol, iters = sor(A, b, omega=1.2)
28
# Prints approx [ 38.14 155.67 291.75]
29
print(np.round(sol, 2), "in", iters, "iterations")
3.5 Convergence: When Do These Methods Work?
Diagonal Dominance: Jacobi and Gauss-Seidel converge if:
|aii | > ∑ |ai j | for all rows i
j̸=i
The diagonal element must be bigger than the sum of all other elements in that row.
4 1 1
Check the Sonatrach matrix: A = 1 5 2
1 2 6
Row 1: |4| > |1| + |1| = 2 ⇒ 4 > 2 ✓
Row 2: |5| > |1| + |2| = 3 ⇒ 5 > 3 ✓
Row 3: |6| > |1| + |2| = 3 ⇒
6>3✓
All rows pass ⇒ Jacobi and Gauss-Seidel will converge!
Stopping rule: Stop when ∥x(k+1) − x(k) ∥ < ε , where ε is a small number like 10−6 .
Spectral radius: Converges if ρ (T ) < 1, where ρ (T ) is the biggest |eigenvalue| of the iteration matrix T .
4 Eigenvalues and Eigenvectors
4.1 What Are Eigenvalues?
For a matrix A, if A v = λ v (with v ̸= 0), then:
• λ (lambda) is an eigenvalue = a special number
• v is an eigenvector = a special direction
In simple words: multiply A by v, and the result is just v made bigger or smaller by λ .
How to find: Solve det(A − λ I) = 0 (characteristic equation).
Why eigenvalues matter in Algeria:
• Jumia: Eigenvalues help rank which product categories grow the fastest.
• Sonatrach: In data analysis, eigenvalues tell which factor matters most (oil price? production volume? transport
cost?).
• Yassir: Eigenvalues of a traffic matrix show if traffic is stable or will get worse.
4.1.1 Example: Eigenvalues 2×2 (Djezzy Subscriber Growth)
Djezzy tracks subscribers and revenue. Growth matrix:
4 1
A=
2 3
4 − λ
Step 1: A − λ I =
2
1
3−λ
Step 2: det(A − λ I) = (4 − λ )(3 − λ ) − 2 = λ 2 − 7λ + 10 = 0
Step 3: (λ − 5)(λ − 2) = 0 ⇒ λ1 = 5 and λ2 = 2
Step 4: Eigenvectors
−1 1
For λ1 = 5: (A − 5I)v = 0 ⇒
v = 0 ⇒ v1 = v2 ⇒ v1 = (1, 1)
2 −2
2 1
For λ2 = 2: (A − 2I)v = 0 ⇒
v = 0 ⇒ v2 = −2v1 ⇒ v2 = (1, −2)
2 1
λ1 = 5, v1 = (1, 1): subscribers and revenue grow together. Dominant growth rate = 5×.
Interpretation: The dominant eigenvalue λ1 = 5 tells Djezzy: “In the long run, both subscribers and revenue grow by
a factor of 5 each period.” The eigenvector (1, 1) means they grow at the same rate – when you gain subscribers, revenue
follows equally. The second eigenvalue λ2 = 2 with eigenvector (1, −2) represents a temporary pattern where subscribers
go up but revenue goes down (maybe from free promotions). Since λ1 > λ2 , the first pattern dominates over time. Djezzy
managers use this to predict: long-term growth is stable and balanced.
Python implementation – eigenvalues & eigenvectors:
1
import numpy as np
2
3
# Djezzy growth matrix
4
A = np.array([[4, 1], [2, 3]], dtype=float)
5
6
# numpy computes ALL eigenvalues and eigenvectors at once
7
eigvals, eigvecs = np.linalg.eig(A)
8
# eigvals -> [5. 2.]
9
print("eigenvalues:", eigvals)
10
# Each COLUMN of eigvecs is the eigenvector for the matching eigenvalue
11
print("eigenvectors (columns):\n", eigvecs)
(the special scaling numbers lambda)
12
13
# Manual check via the characteristic equation lambda^2 - 7 lambda + 10 = 0
14
# np.roots takes polynomial coefficients [1, -7, 10]
15
print("roots of char. eq.:", np.roots([1, -7, 10]))
# -> [5. 2.]
4.1.2 Gershgorin’s Circle Theorem
Every eigenvalue is inside at least one Gershgorin disc:
• Center = aii (diagonal element)
• Radius = Ri = ∑ j̸=i |ai j |
You know where eigenvalues are without computing them!
10 1 0
Mobilis Performance Matrix: A = 0 6 2
1 0 8
Disc 1: Center = 10, Radius = 1 ⇒ eigenvalue in [9, 11]
Disc 2: Center = 6, Radius = 2 ⇒ eigenvalue in [4, 8]
Disc 3: Center = 8, Radius = 1 ⇒ eigenvalue in [7, 9]
Without any big calculation: all eigenvalues are between 4 and 11.
4.2 Power Method
Goal: Find the biggest eigenvalue (dominant) and its eigenvector.
Algorithm:
1. Pick any starting vector x(0) ̸= 0
2. Compute y(k) = A × x(k)
3. Find biggest element: µ (k) = max |y(k) |
4. Normalize: x(k+1) = y(k) /µ (k)
5. Repeat until µ (k) stops changing
4.2.1 Example: Power Method (Yassir Traffic)
Yassir traffic between 2 zones in Algiers (Bab El Oued ↔ Hussein Dey):
2 1
A=
1 3
x(0) = (1, 1)
2(1) + 1(1)
Iteration 1: multiply y = Ax(0) =
= [3, 4]. Biggest = µ = 4. Divide by it: x(1) = [3/4, 4/4].
1(1) + 3(1)
(1) = (0.75, 1)
Output after iteration 1: µ= 4.000, x
2(0.75) + 1
Iteration 2: y = Ax(1) =
= [2.5, 3.75]. µ = 3.75, divide: x(2) = [2.5/3.75, 1].
0.75 + 3
Output after iteration 2: µ= 3.750, x(2) = (0.667, 1)
2(0.667) + 1
Iteration 3: y = Ax(2) =
= [2.333, 3.667]. µ = 3.667, divide: x(3) = [0.636, 1].
0.667 + 3
Output after iteration 3: µ= 3.667, x(3) = (0.636, 1)
2(0.636) + 1
Iteration 4: y = Ax(3) =
= [2.273, 3.636]. µ = 3.636, divide: x(4) = [0.625, 1].
0.636 + 3
Output after iteration 4: µ = 3.636, x(4) = (0.625, 1)
Iteration
µ (eigenvalue)
x (eigenvector)
1
4.000
(0.750, 1)
2
3.750
(0.667, 1)
3
3.667
(0.636, 1)
4
3.636
(0.625, 1)
∞
3.618
(0.618, 1)
Dominant eigenvalue ≈ 3.618. Traffic grows by 3.618× each cycle. Hussein Dey gets 1.6x more traffic than Bab El
√
Oued. Exact: λ = (5 + 5)/2.
Interpretation: The eigenvalue 3.618 means traffic grows fast – it multiplies by 3.6 each hour. The eigenvector
(0.618, 1) tells Yassir that Hussein Dey always gets more traffic than Bab El Oued (ratio ≈ 1.6 : 1). So Yassir should
place 60% more drivers in Hussein Dey. The power method found this answer in just 4 iterations – very fast! Each iteration
is like observing one hour of traffic and updating the model. Note: if λ > 1, traffic grows (congestion risk). If λ < 1, traffic
decreases (zone is quiet).
The iterations are approximate. µ goes 4 → 3.75 → 3.667 → 3.636 → . . . getting closer to the exact value λ =
√
5+ 5
= 3.6180 . . . each step. It never lands exactly on it in finite steps – we stop once µ stops changing to the accuracy
2
we need. The eigenvector likewise approaches the exact (0.618, 1) where 0.618 =
Python implementation – Power method:
1
import numpy as np
2
3
# Find the dominant (biggest) eigenvalue of A and its eigenvector
4
def power_method(A, x, tol=1e-6, max_iter=100):
5
# mu_old = previous eigenvalue estimate (start at 0)
6
mu_old = 0.0
7
for k in range(max_iter):
8
# Multiply the matrix by the current vector
9
y = A @ x
10
# mu = the entry of y with the largest absolute value
11
mu = y[np.argmax(np.abs(y))]
12
# Normalize so the largest component becomes 1 (keeps numbers stable)
13
x = y / mu
14
# Stop when the eigenvalue estimate barely moves
15
if abs(mu - mu_old) < tol:
16
return mu, x, k + 1
17
# Remember this estimate for the next comparison
18
mu_old = mu
19
return mu, x, max_iter
20
21
# Yassir 2-zone traffic matrix, starting vector (1, 1)
22
A = np.array([[2, 1], [1, 3]], dtype=float)
23
x0 = np.array([1, 1], dtype=float)
24
val, vec, iters = power_method(A, x0)
25
# Prints approx 3.618 and eigenvector approx [0.618 1.]
√
5−1
(the golden ratio).
2
26
print(round(val, 3), np.round(vec, 3), "in", iters, "iterations")
5 Matrix Analysis
5.1 Vector Spaces
A vector space is a set of vectors where you can:
1. Add two vectors → result stays in the set
2. Multiply a vector by a number → result stays in the set
Rules: u + v = v + u, zero vector exists, every vector has an opposite.
Algerian CS examples:
• Jumia: Each product = vector of features (price, weight, rating). Machine learning uses this to find similar
products.
• Yassir: Each driver position = vector (x, y). All positions form R2 .
Key terms: Linear independence = no vector is a mix of others. Basis = smallest set that builds everything.
Dimension = number of basis vectors.
5.2 Matrices
5.2.1 Operations on Matrices
Condor Electronics
–Addition:Two months
of TV sales (rows = models, columns = wilayas):
120 180
100 200
Jan =
, Feb =
200 250
150 300
220 380
Total:
350 550
240 360
Forecast March (2× Feb):
400 500
Sonatrach
worked (2 engineers, 2 projects). B = pay rate.
A = hours
– Multiplication:
20 30
10 5
A=
, B =
25 15
8 12
A × B: each entry = row × column:
c11 = 10 × 20 + 5 × 25 = 325
c12 = 10 × 30 + 5 × 15 = 375
c21 = 8 × 20 + 12 × 25 = 460
c22 = 8 × 30 + 12 × 15 = 420
325 375
A×B =
(thousands DZD per engineer per division)
460 420
Important: A × B ̸= B × A in general! Order matters!
5.2.2 Linear Maps and Matrices
Every linear map f : Rn → Rm can be written as f (x) = Ax.
0 −1
Yassir – Rotation: Rotate the map by 90°: R =
1 0
A−1 is the matrix where
× A−1 = I. Exists only
A
if det(A)̸= 0.
3 1
Djezzy – 2×2 Inverse: A =
5 2
det(A)
= 3 × 2 − 1× 5 = 1
2 −1
−5 3
A−1 =
6 − 5 −3 + 3 1 0
Verify: A × A−1 =
✓
=
0 1
10 − 10 −5 + 6
3 −1
Driver at (3, 1): R × =
1
3
5.2.3 Inverse of a Matrix
a b
d −b
1
For 2 × 2: A =
⇒ A−1 =
ad − bc
c d
−c a
1 2 3
Jumia – 3×3 Inverse (Gauss-Jordan): A = 0 1 4
5 6 0
Write [A | I] and transform to [I | A−1 ]:
1 0 0
3
1 2
1 2 3 1 0 0
R3 −5R1
0 1 4 0 1 0 −−−−→ 0 1
4
0
1
0
0 −4 −15 −5 0 1
5 6 0 0 0 1
1 2 3 1 0 0
R3 +4R2
−−−−→ 0 1 4 0 1 0
0 0 1 −5 4 1
1 2 0 16 −12 −3
R2 −4R3 , R1 −3R3
−−−−−−−−−→ 0 1 0 20 −15 −4
4
1
0 0 1 −5
5
1 0 0 −24 18
R1 −2R2
−−−−→ 0 1 0 20 −15 −4
0 0 1 −5
4
1
5
−24 18
−1
A = 20 −15 −4
−5
4
1
Interpretation: The inverse matrix lets Jumia solve x = A−1 b for any sales vector b instantly. For example, if tomorrow
Jumia has new sales data b = [100, 200, 150], they just multiply: x = A−1 × b – one matrix multiplication gives the answer.
Without A−1 , they would need to redo Gauss elimination every time. The large values in A−1 (like −24 and 20) suggest the
system is sensitive – small changes in sales data cause big changes in the answer. Jumia should check the condition number
to be safe.
5.2.4 Trace and Determinant
Trace: tr(A) = a11+ a22
+ . . . + ann (sum of diagonal)
a b
Det 2 × 2: det
= ad − bc
c d
Det 3 × 3: det(A) = a11 (a22 a33 − a23 a32 ) − a12 (a21 a33 − a23 a31 ) + a13 (a21 a32 − a22 a31 )
1 2 3
A = 4 5 6
7 8 9
det = 1(45 − 48) − 2(36 − 42) + 3(32 − 35) = −3 + 12 − 9 = 0
det = 0 ⇒ no inverse (singular matrix).
5.2.5 Eigenvalue Properties
• Sum of eigenvalues = trace(A)
• Product of eigenvalues = det(A)
• Triangular matrix: eigenvalues = diagonal elements
• Symmetric matrix (A = AT ): all eigenvalues are real
5.2.6 Similar Matrices
A and B are similar if B = P−1 AP for some invertible P. Same eigenvalues, det, trace.
5.2.7 Special Matrices
Type
Rule
Symmetric
A = AT
Diagonal
Only diagonal ̸= 0
Identity
Diagonal = 1, rest = 0
Orthogonal
A−1 = AT
Positive Definite
xT Ax > 0 for x ̸= 0
2 1
1 3
Sparse
Most elements = 0
Road networks
5.3 Norms and Scalar Products
5.3.1 What is a Norm?
A norm measures the “size” of a vector. Rules:
1. ∥x∥ ≥ 0 and ∥x∥ = 0 only if x = 0
2. ∥α x∥ = |α | · ∥x∥
3. ∥x + y∥ ≤ ∥x∥ + ∥y∥ (triangle inequality)
5.3.2 Scalar Product and Vector Norms
Scalar (dot) product: ⟨x, y⟩ = x1 y1 + x2 y2 + . . . + xn yn
Example
2 3
3 5
4 0
0 7
1 0
I=
0 1
Rotation matrix
Norm
Formula
Algerian CS Meaning
1-norm (Manhattan)
∥x∥1 = ∑ |xi |
Street distance in Algiers (Yassir)
2-norm (Euclidean)
∥x∥2 =
∞-norm (Max)
∥x∥∞ = max |xi |
q
∑ xi2
GPS distance (straight line)
Worst-case error
Yassir Example: Driver at Place des Martyrs (0, 0), client at Ain Naadja (3, −4):
1-norm (street distance): |3| + | − 4| = 7 km
2-norm (GPS straight):
√
9 + 16 = 5 km
∞-norm (farthest direction): max(3, 4) = 4 km
Example: All 3 norms of x = (1, −2, 3):
∥x∥1 = |1| + | − 2| + |3| = 6
∥x∥2 =
5.3.3 Matrix Norms
• ∥A∥1 = max column sum = max j ∑i |ai j |
• ∥A∥∞ = max row sum = maxi ∑ j |ai j |
• ∥A∥2 =
• ∥A∥F =
p
largest eigenvalue of AT A (spectral norm)
q
∑i, j a2i j (Frobenius norm)
1 −2 3
A=
4 5 −6
∥A∥1 : Col 1 = 5, Col 2 = 7, Col 3 = 9 ⇒ 9
∥A∥∞ : Row 1 = 6, Row 2 = 15 ⇒ 15
∥A∥F :
√
√
1 + 4 + 9 + 16 + 25 + 36 = 91 ≈ 9.539
√
√
1 + 4 + 9 = 14 ≈ 3.742
∥x∥∞ = 3
Summary: All Key Formulas
Topic
Method
Key Idea
Errors
Absolute / Relative
|exact − approx| and ratio
Direct
Gauss Elimination
Row ops → triangular → back-sub
Direct
LU Factorization
A = LU, solve Ly = b then Ux = y
Iterative
Jacobi
All old values
Iterative
Gauss-Seidel
Use new values immediately
Iterative
SOR
(1 − ω )x(k) + ω · GS
Convergence
Diag. Dominance
|aii | > ∑ j̸=i |ai j |
Eigenvalues
Charact. Eq.
det(A − λ I) = 0
Eigenvalues
Power Method
Multiply by A, normalize
Eigenvalues
Gershgorin
Center = aii , Radius = ∑ |ai j |
Matrix
Inverse 2 × 2
(1/ det) × [d, −b; −c, a]
Norms
1-norm
∑ |xi | (street distance)
Norms
2-norm
Norms
∞-norm
q
∑ xi2 (GPS straight)
max |xi |
Evaluation: Final Exam (60%) + Continuous Assessment (40%)
Semester 3 | Credits: 4 | Coefficient: 2
0
You can add this document to your study collection(s)
Sign in Available only to authorized usersYou can add this document to your saved list
Sign in Available only to authorized users(For complaints, use another form )