Definition. A Matrix Is Upper-Triangular If - 0 0 0 - 0 0 - . - . 0 - . - .

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Definition. A matrix A = (aij ) is upper-triangular if aij = 0 i > j .

a11

0
0

Algorithm.

a 22
0
0

a n 1,n

a nn
a1n
a2n
.
.
.


0 0 a n 1,n 1
0 0
0

Backward Substitution.

Given the upper-triangular nxn matrix A with a[i][i] != 0.0 (i = 1,...n)


and the n-vector b. Construct the entries x[n], x[n-1],...,x[1] of the
solution vector x of Ax = b.

for (k = n; k > 0; k--) {


x[k] = b[k];
for (j = k+1; j <= n; j++)
x[k] = x[k] a[k][j]*x[j];
//endfor j
x[k] = x[k] / a[k][k];
}//endfor k

bk
Note: The k-loop body performs x k =

j = k +1

a kk

kj

xj
.

Algorithm.

Gaussian Elimination (with pivoting when necessary)

Start with Ax = b where A is an nxn matrix and b is an n-vector.


On exit, Ax = b will be an equivalent system with A upper-triangular.
for (k = 1; k < n; k++) { // Eliminate column k below the main diagonal.
find the smallest i (i >= k) such that a[i][k] != 0.0;
if no such i exists
return "not invertible";
//endif
exchange rows k and i; // called "pivoting"
for (i = k+1; i <= n; i++) { // Process row i.
m[i][k] = a[i][k] / a[k][k];
for (j = k+1; j <= n; j++) // Alter column j of row i.
a[i][j] = a[i][j] m[i][k]*a[k][j];
//endfor j
b[i] = b[i] m[i][k]*b[k];
}//endfor i
}//endfor k
if (a[n][n] == 0.0)
return "not invertible";
//endif

Notes:
1) Step k eliminates column k below the main diagonal, working on rows
i = k+1, k+2, , n.
a
2) The i-loop performs ROW # i = ROW # i ik ROW # k , modifying columns
a kk
j = k+1, k+2, , n and then the right hand side.
3) smallest i?? This just says to select the very first non-zero column k entry you come
upon, first looking at row k, then row k+1 if necessary, then row k+2, etc.
Summary: To solve Ax = b ,
1) Apply the Gaussian Elimination algorithm to convert to an upper-triangular system.
2) Do the backward substitution algorithm on the upper-triangular part of A .

Solving Ax = b by Gaussian elimination and backward substitution in Matlab requires


only a single simple statement:
x = A\b

You might also like