Scalable Tissue Imaging and Modeling (STIM) Laboratory
Department of Electrical and Computer Engineering
Cullen College of Engineering
University of Houston
David Mayerich
STIM Laboratory, University of Houston
Roundoff in Gaussian Elimination
Partial Pivoting
Pivoting Strategies
David Mayerich
STIM Laboratory, University of Houston
What is the exact solution to the following linear system using 3 digits of precision?
David Mayerich
STIM Laboratory, University of Houston
What is the exact solution to the following linear system using 3 digits of precision?
David Mayerich
STIM Laboratory, University of Houston
The pivot row is scaled to eliminate leading coefficients in other rows
David Mayerich
STIM Laboratory, University of Houston
Select the pivot equation with the largest leading coefficient and swap rows
Perform row reduction
The pivot row is scaled to eliminate leading coefficients in other rows
David Mayerich
STIM Laboratory, University of Houston
Select the pivot equation with the largest leading coefficient and swap rows
Perform row reduction
David Mayerich
STIM Laboratory, University of Houston
Gaussian Elimination
Partial Pivoting
Swapping is slow: introduces an \(O(n)\) memory copy every iteration:
David Mayerich
STIM Laboratory, University of Houston
Swapping is slow: introduces an \(O(n)\) memory copy every iteration:
David Mayerich
STIM Laboratory, University of Houston
Swapping is slow: introduces an \(O(n)\) memory copy every iteration:
David Mayerich
STIM Laboratory, University of Houston
Swapping is slow: introduces an \(O(n)\) memory copy every iteration:
David Mayerich
STIM Laboratory, University of Houston
Swapping is slow: introduces an \(O(n)\) memory copy every iteration:
David Mayerich
STIM Laboratory, University of Houston
Use an \(n\)-dimensional index vector \(\ell \in \mathbb{N}^n\)
int i = 2 // row index
int j = 1 // column index
// direct access
x = C[i * n + j]; // x = a_21
// indirect access
y = C[l[i] * n + j]; // y = a_n1
David Mayerich
STIM Laboratory, University of Houston
void gaussian(double* A, double* b, int N){
for(int k=0; k<N-1; k++){ // for each pivot
for(int i=k+1; i<N; i++){ // for each equation
float m=A[i*N+k] / A[k*N+k]; // calculate scale
for(int j=k; j<N; j++){ // for each coefficient
A[i*N+j] -= m * A[k*N+j]; // subtract
}
b[i] -= m * b[k]; // forward elimination
}
}
}David Mayerich
STIM Laboratory, University of Houston
void ppivot(double* A, double* b, int N){
int* L;
init(L); // initialize the index vector
for(int k=0; k<N-1; k++){ // for each pivot
for(int i=k+1; i<N; i++){ // for each equation
float m=A[i*N+k] / A[k*N+k]; // calculate scale
for(int j=k; j<N; j++){ // for each coefficient
A[i*N+j] -= m * A[k*N+j]; // subtract
}
b[i] -= m * b[k]; // forward elimination
}
}
}David Mayerich
STIM Laboratory, University of Houston
void ppivot(double* A, double* b, int N){
int* L;
init(L); // initialize the index vector
for(int k=0; k<N-1; k++){ // for each pivot
int p = select_pivot(A, L, k, N); // select the best pivot
for(int i=k+1; i<N; i++){ // for each equation
float m=A[i*N+k] / A[k*N+k]; // calculate scale
for(int j=k; j<N; j++){ // for each coefficient
A[i*N+j] -= m * A[k*N+j]; // subtract
}
b[i] -= m * b[k]; // forward elimination
}
}
}David Mayerich
STIM Laboratory, University of Houston
void ppivot(double* A, double* b, int N){
int* L;
init(L); // initialize the index vector
for(int k=0; k<N-1; k++){ // for each pivot
int p = select_pivot(A, L, k, N); // select the best pivot
swap(L, p, k); // swap indices
for(int i=k+1; i<N; i++){ // for each equation
float m=A[i*N+k] / A[k*N+k]; // calculate scale
for(int j=k; j<N; j++){ // for each coefficient
A[i*N+j] -= m * A[k*N+j]; // subtract
}
b[i] -= m * b[k]; // forward elimination
}
}
}David Mayerich
STIM Laboratory, University of Houston
void ppivot(double* A, double* b, int N){
int* L;
init(L); // initialize the index vector
for(int k=0; k<N-1; k++){ // for each pivot
int p = select_pivot(A, L, k, N); // select the best pivot
swap(L, p, k); // swap indices
for(int i=k+1; i<N; i++){ // for each equation
float m=A[L[i]*N+k] / A[L[k]*N+k];// calculate scale
for(int j=k; j<N; j++){ // for each coefficient
A[L[i]*N+j] -= m * A[L[k]*N+j]; // subtract
}
b[L[i]] -= m * b[L[k]]; // forward elimination
}
}
}Scaled Partial Pivoting
Full Pivoting
David Mayerich
STIM Laboratory, University of Houston
David Mayerich
STIM Laboratory, University of Houston
Using partial pivoting, \(r_2\) will be selected as the first pivot, resulting in:
Divide each equation by its largest coefficient:
David Mayerich
STIM Laboratory, University of Houston
Applying partial pivoting to this scaled matrix yields:
Use the scaled coefficient to select the pivot, but don't actually apply scaling:
David Mayerich
STIM Laboratory, University of Houston
w/ scaling
Swap rows and columns to optimize for the largest coefficient:
David Mayerich
STIM Laboratory, University of Houston
Partial pivoting:
David Mayerich
STIM Laboratory, University of Houston
Scaling with partial pivoting:
Scaled partial pivoting (use the scale to select the pivot):
Full pivoting:
Solving Multiple Right-Hand Sides
Matrix Factorization
Benefits for LU Decomposition
David Mayerich
STIM Laboratory, University of Houston
Consider row reduction of the following matrix:
David Mayerich
STIM Laboratory, University of Houston
This can be encoded in the matrix multiplication:
unitriangular
matrix
A matrix \(\mathbf{A}\) is unitriangular if it is:
all diagonal elements are one
all lower-left or upper-right are zero
David Mayerich
STIM Laboratory, University of Houston
The inverse of a unitriangular matrix is:
(negate all non-zero off-diagonal elements)
We can perform row reduction using a unidiagonal matrix of scale factors:
David Mayerich
STIM Laboratory, University of Houston
And invert that process using the inverse matrix:
LU Decomposition is the process of factorizing a matrix \(\mathbf{A}=\mathbf{L}\mathbf{U}\) into a lower unitriangular matrix \(\mathbf{L}\) and an upper triangular matrix \(\mathbf{U}\)
David Mayerich
STIM Laboratory, University of Houston
Given a matrix \(\mathbf{A}\), calculate \(\mathbf{L}\) and \(\mathbf{U}\):
Initialize \(\mathbf{L}_0 = \mathbf{I}\) with the identity matrix
Perform Gaussian elimination of \(\mathbf{A}\), which produces \(\mathbf{U}\)
For each iteration \(n\) of Gaussian elimination, store the scale factors in \(\mathbf{L}_n\)
David Mayerich
STIM Laboratory, University of Houston
lu_decomposition(double* A, double* L, int N){
identity(L, N); // initialize L
for(int k=0; k<N-1; k++){ // for each pivot
for(int i=k+1; i<N; i++){ // for each equation
float m=A[i*N+k] / A[k*N+k]; // calculate scale
L[i*N+k] = m; // store the scale factor
for(int j=k; j<N; j++){ // for each coefficient
A[i*N+j] -= m * A[k*N+j]; // subtract
}
}
}
}Solve the following two linear systems:
David Mayerich
STIM Laboratory, University of Houston
Using a direct method would require \(O(n)\) time for each system
What is the complexity for solving a linear system \(\mathbf{A}\mathbf{x}=\mathbf{b}\) if \(\mathbf{A}\) is triangular?
Factorize \(\mathbf{A}\) and solve:
LU decomposition:
Solve for \(\mathbf{z}=\mathbf{Ux}\):
Solve for \(\mathbf{x}\):
David Mayerich
STIM Laboratory, University of Houston