17 Complexity Matrix Operations
17 Complexity Matrix Operations
2024/04/19
Goals
We assess the computational cost of matrix operations such as products, back
substitution, and Gaussian elimination. We assume that the number of floating-
point operations (FLOPS) required to perform a given operation is proportional
to the computational cost. Other factors such as memory usage are as important
in some cases.
We compare the cost of direct and iterative methods for the solution of linear
systems. We conclude that iterative methods may be much more efficient than
direct methods for large sparse systems.
Dot Product
For a, b ∈ RN computing the dot product
N
X
a·b= ai bi
i=1
2N − 1
Big O Notation
Let f : N → R and g : N → [0, ∞). We write
f (N ) = O(g(N )) as N → ∞
1
iff for some N0 ∈ N and some constant C > 0 we have
f (N ) = 2N − 1
f (N ) = O(N ).
vi = Mi: · v.
We take one such dot product for each row of M , and computing each dot
product requires 2N − 1 operations. Thus, we require
M (2N − 1)
operations to compute M v.
If M ∈ RN ×N is square, then the number of operations is
N (2N − 1) = O(N 2 ).
Back Substitution
To solve an upper-triangular system
2
A11 x1 + A12 x2 + · · · + A1N xN = b1
A22 x2 + · · · + A2N xN = b2
..
.
AN N x N = bN ,
AN −1,N −1 xN −1 + AN −1,N xN = bN −1 .
xN −1 = A−1
N −1,N −1 (bN −1 − AN −1,N xN ).
xN −k = A−1
N −k,N −k (bN −k −AN −k+1 xN −k+1 −AN −k+2 xN −k+2 −. . . AN −k,N xN ).
N −1
X N (N − 1)
2k + 1 = 2 +N = O(N 2 ).
2
k=0 | {z }
sum of integers k from zero to N − 1
2 3
PLU FLOPS ∼ N
3
for a matrix of size N × N .
3
Householder QR Factorization
The cost to compute the QR-factorization by the Householder method is
4 3
QR FLOPS ∼ N .
3
N
X −1
2 × (2 multiplications + 1 addition ) + (3 multiplications + 2 additions ) = O(N ).
| {z }
k=2
1’st and N ’th rows | {z }
2’d through N − 1’st rows
4
FLOPS for Sparse PLU and QR
It can be very difficult to take advantage of sparsity when computing the QR or
PLU decomposition of a matrix.
This is essentially because the inverse of a sparse matrix need not be sparse, and
the factors Q, R, L, and U need not be sparse.
Matrix factorizations usually cost O(N 3 ) for sparse matrices unless you do
something very clever.
There are a exceptions for sparse matrices of special forms.
For example, the tridiagonal matrix algorithm computes solutions of tridiagonal
systems (such as the mass-spring) at O(n) cost.
5
∥x̃ − x∥∞ ≤ ϵ.
Recall our error estimate for classical iterations: If ∥I − P A∥∞ < 1, then the
iteration is convergent and
To estimate the number of steps required to acheive precision ϵ, we can find the
smallest m so that
∥I − P A∥m
∞ ∥x0 − x∥∞ ≤ ϵ.
Since we assume ∥I − P A∥∞ < 1, we have ln(∥I − P A∥∞ ) < 0, and therefore
the above equation is equivalent with
ln(ϵ/∥x0 − x∥∞ )
m≥ .
ln(∥I − P A∥∞ )
ln(ϵ/∥x0 − x∥∞ )
× FLOPS for one step.
ln(∥I − P A∥∞ )