Algorithms Flops
Algorithms Flops
Algorithms
Krithika Narayanaswamy
• A is a n × n matrix
• The system being solved is Ax = b
• L and U refer to Lower triangular and Upper triangular matrices respectively.
• Any index range refer to all numbers in that range. For instance, k + 1 : n refers to the range of numbers
k + 1, k + 2, . . . n. Note that this interpretation also applies to such ranges that appear in the row/column indices
of matrices.
U = A, L = I
for k = 1 : n − 1 do
for j = k + 1 : n do
ljk = ujk /ukk (Multiplication factor)
ujk = 0 (Element underneath pivot)
uj,k+1:n = uj,k+1:n − ljk · uk,k+1:n (Row operations)
bj = bj − ljk bk (Row operations on rhs vector)
end
end
U = A, L = I
for k = 1 : n − 1 do
for j = k + 1 : n do
ljk = ujk /ukk (Multiplication factor)
ujk = 0 (Element underneath pivot)
uj,k+1:n = uj,k+1:n − ljk · uk,k+1:n (Row operations)
end
end
Remarks:
1. Row operations are being performed only on columns k + 1 : n on the j th row. This is because
U =A
for k = 1 : n − 1 do
Select q : |uq,k | = max |up,k |
p≥k
uk,k:n ↔ uq,k:n (Row swap)
for j = k + 1 : n do
mult = ujk /ukk (Multiplication factor)
ujk = 0 (Element underneath pivot)
uj,k+1:n = uj,k+1:n − mult · uk,k+1:n (Row operations)
bj = bj − mult · bk (Row operations on rhs vector)
end
end
U = A, L = I, P = I
for k = 1 : n − 1 do
Select q : |uq,k | = max |up,k |
p≥k
uk,k:n ↔ uq,k:n (Row swap in U matrix)
lk,1:k−1 ↔ lq,1:k−1 (Row swap in L matrix)
pk,1:n ↔ pq,1:n (Row swap in permutation matrix)
for j = k + 1 : n do
ljk = ujk /ukk (Multiplication factor)
ujk = 0 (Element underneath pivot)
uj,k+1:n = uj,k+1:n − ljk · uk,k+1:n (Row operations)
end
end
Exercise:
1. Using the above algorithm, given matrix A as,
2 1 1
A = 4 3 3
8 7 9
obtain the L, U , and P matrices.
2. Verify that P A = LU .