You are on page 1of 25

Linear Algebraic Equations and

Matrices

©McGraw-Hill Education.
Overview, 1
A matrix consists of a rectangular array of elements
represented by a single symbol (example: [A]).

An individual entry of a matrix is an element


(example: a23)

©McGraw-Hill Education.
Overview, 2
A horizontal set of elements is called a row and a
vertical set of elements is called a column.

The first subscript of an element indicates the row


while the second indicates the column.

The size of a matrix is given as m rows by n


columns, or simply m by n (or m x n).

1 x n matrices are row vectors.

m x 1 matrices are column vectors.

©McGraw-Hill Education.
Special Matrices
Matrices where m=n are called square matrices.
There are a number of special forms of square
matrices:
Symmetric Diagonal Identity
5 1 2 𝑎11 1
𝐴 = 1 3 7 𝐴 = 𝑎22 𝐴 = 1
2 7 8 𝑎33 1

Upper Triangular Lower Triangular Banded


𝑎11 𝑎12 𝑎13 𝐴 𝑎11 𝑎12
𝐴 = 𝑎22 𝑎23 𝑎11 𝑎 𝑎22 𝑎23
𝐴 = 21
𝑎33 = 𝑎21 𝑎22 𝑎32 𝑎33 𝑎34
𝑎31 𝑎32 𝑎33 𝑎43 𝑎44

©McGraw-Hill Education.
Matrix Operations
Two matrices are considered equal if and only if
every element in the first matrix is equal to every
corresponding element in the second. This means
the two matrices must be the same size.

Matrix addition and subtraction are performed by


adding or subtracting the corresponding elements.
This requires that the two matrices be the same size.

Scalar matrix multiplication is performed by


multiplying each element by the same scalar.

©McGraw-Hill Education.
Matrix Multiplication
The elements in the matrix [C] that results from
multiplying matrices [A] and [B] are calculated using:
-

𝑐𝑖𝑗 = # 𝑎𝑖𝑘𝑏𝑘𝑗
*+,

©McGraw-Hill Education.
Matrix Inverse and Transpose
The inverse of a square, nonsingular matrix
[A] is that matrix which, when multiplied by
[A], yields the identity matrix.
• [A][A]-1=[A]-1[A]=[I]
• In Matlab: inv(A)
The transpose of a matrix involves
transforming its rows into columns and its
columns into rows.
• (aij)T=aji
• In Matlab: A'
©McGraw-Hill Education.
Representing Linear Algebra
Matrices provide a concise notation for
representing and solving simultaneous linear
equations:

𝑎11𝑥1 + 𝑎12𝑥2 + 𝑎13𝑥3 = 𝑏1 𝑎11 𝑎12 𝑎13 𝑥1 𝑏1


𝑎21 𝑎22 𝑎23 𝑥2 𝑏2
𝑎21𝑥1 + 𝑎22𝑥2 + 𝑎23𝑥3 = 𝑏2
𝑎31 𝑎32 𝑎33 𝑥3 𝑏3
𝑎31𝑥1 + 𝑎32𝑥2 + 𝑎33𝑥3 = 𝑏3

𝐴 𝑥 = {𝑏}

©McGraw-Hill Education.
Solving With MATLAB
MATLAB provides two direct ways to solve
systems of linear algebraic equations
[A]{x}={b}:
• Left-division
x = A\b
• Matrix inversion
x = inv(A)*b
The matrix inverse is less efficient than left-
division and also only works for square, non-
singular systems.
©McGraw-Hill Education.
Graphical Method, 1
For small sets of
simultaneous
equations, graphing
them and
determining the
location of the
intercept provides a
solution.

©McGraw-Hill Education.
Graphical Method, 2
Graphing the equations can also show systems
where:
a) No solution exists
b) Infinite solutions exist
c) System is ill-conditioned

ILL-CONDITIONED
SINGULAR
©McGraw-Hill Education.
Determinants
The determinant D=|A| of a matrix is formed from the
coefficients of [A].

Determinants for small matrices are:


1×1 𝑎11 = 𝑎11

𝑎11 𝑎12
2×2 = 𝑎11𝑎22 − 𝑎12𝑎21
𝑎21 𝑎22
𝑎11 𝑎12 𝑎13
𝑎22 𝑎23 𝑎21 𝑎23 𝑎21 𝑎22
3×3 𝑎21 𝑎22 𝑎23 = 𝑎11 − 𝑎12 + 𝑎13
𝑎32 𝑎33 𝑎31 𝑎33 𝑎31 𝑎32
𝑎31 𝑎32 𝑎33

Determinants for matrices larger than 3 x 3 can be very


complicated.
©McGraw-Hill Education.
a11 x1 + a12 x2 = b1 ® ´ ( -a21 ) - a21a11 x1 - a21
a21 x1 + a22 x2 = b2 ® ´ ( a11 ) a11a21 x1 + a11a

Look at basic elimination


a11 x1 + a12 x2 = b1 ® ´ ( -a21 ) - a21a11 x1 - a21a12 x2 = -a21b1
a21 x1 + a22 x2 = b2 ® ´ ( a11 ) a11a21 x1 + a11a22 x2 = a11b2

Adding together
( a11a22 - a21a12 ) x2 = a11b2 - a21b1
x2 =
( a11b2 - a21b1 )
( a11a22 - a21a12 )
Same equation we will get for x1

©McGraw-Hill Education.
a11 x1 + a12 x2 = b1 ® ´ ( -a21 ) - a21a11 x1 - a21
a21 x1 + a22 x2 = b2 ® ´ ( a11 ) a11a21 x1 + a11a
𝑎11 𝑎12
𝐷= = 𝑎11𝑎22 − 𝑎12𝑎21
𝑎21 𝑎22
𝑏 𝑎12
𝐷!! = 1 = 𝑏1𝑎22 − 𝑎12𝑏2
𝑏2 𝑎22
𝑎 𝑏1
𝐷!" = 11 = 𝑎11𝑏2 − 𝑏1𝑎21
𝑎21 𝑏2

𝐷!! 𝑏1𝑎22 − 𝑎12𝑏2


𝑥" = =
𝐷 𝑎11𝑎22 − 𝑎12𝑎21 Cramer’s Rule
𝐷!" 𝑎11𝑏2 − 𝑏1𝑎21
𝑥# = =
𝐷 𝑎11𝑎22 − 𝑎12𝑎21

©McGraw-Hill Education.
Cramer’s Rule
Cramer’s Rule states that each unknown in
a system of linear algebraic equations may
be expressed as a fraction of two
determinants with denominator D and with
the numerator obtained from D by replacing
the column of coefficients of the unknown in
question by the constants b1, b2, …, bn.

©McGraw-Hill Education.
Cramer’s Rule Example
Find x2 in the following system of equations:
0.3𝑥1 + 0.52𝑥2 + 𝑥3 = −0.01
0.5𝑥1 + 𝑥2 + 1.9𝑥3 = 0.67
0.1𝑥1 + 0.3𝑥2 + 0.5𝑥3 = −0.44
Find the determinant D
0.3 0.52 1
1 1.9 0.5 1.9 0.5 1
𝐷 = 0.5 1 1.9 = 0.3 − 0.52 +1 = −0.0022
0.3 0.5 0.1 0.5 0.1 0.4
0.1 0.3 0.5
Find determinant D2 by replacing D’s second column with b
0.3 −0.01 1
0.67 1.9 0.5 1.9 0.5 0.67
𝐷2 = 0.5 0.67 1.9 = 0.3 − 0.01 +1 = 0.0649
−0.44 0.5 0.1 0.5 0.1 −0.44
0.1 −0.44 0.5
Divide
𝐷2 0.0649
𝑥2 = = = −29.5
𝐷 −0.0022
©McGraw-Hill Education.
Solving Linear Equations

©McGraw-Hill Education.
Back-substitution

©McGraw-Hill Education.
Naïve Gauss Elimination, 1
For larger systems, Cramer’s Rule can
become unwieldy.
Instead, a sequential process of removing
unknowns from equations using forward
elimination followed by back substitution
may be used—this is Gauss elimination.
“Naïve” Gauss elimination simply means the
process does not check for potential
problems resulting from division by zero.
©McGraw-Hill Education.
Naïve Gauss Elimination, 2
Forward elimination
• Starting with the first row, add or
subtract multiples of that row to
eliminate the first coefficient from the
second row and beyond.
• Continue this process with the second
row to remove the second coefficient
from the third row and beyond.
• Stop when an upper triangular matrix
remains.

Back substitution
• Starting with the last row, solve for the
unknown, then substitute that value
into the next highest row.
• Because of the upper-triangular
nature of the matrix, each row will
contain only one more unknown.
©McGraw-Hill Education.
Naïve Gauss Elimination Program

©McGraw-Hill Education.
Pivoting
Problems arise with naïve Gauss elimination if a
coefficient along the diagonal is 0 (problem:
division by 0) or close to 0 (problem: round-off error)
One way to combat these issues is to determine the
coefficient with the largest absolute value in the
column below the pivot element. The rows can then
be switched so that the largest element is the pivot
element. This is called partial pivoting.
If the rows to the right of the pivot element are also
checked and columns switched, this is called
complete pivoting. But you do not gain much by
doing this!
©McGraw-Hill Education.
Partial Pivoting Program

©McGraw-Hill Education.
Tridiagonal Systems
A tridiagonal system is a banded system with a
bandwidth of 3:
𝑓1 𝑔1 𝑥1 𝑟1
𝑒2 𝑓2 𝑔2 𝑥2 𝑟2
𝑒3 𝑓3 𝑔3 𝑥3 𝑟3
5 5 5 5 5
=
5 5 5 5 5
5 5 5 5 5
𝑒𝑛−1 𝑓𝑛−1 𝑔𝑛−1 𝑥𝑛−1 𝑟𝑛−1
𝑒𝑛 𝑓𝑛 𝑥𝑛 𝑟𝑛

Tridiagonal systems can be solved using the same


method as Gauss elimination, but with much less
effort because most of the matrix elements are
already 0.
©McGraw-Hill Education.
Tridiagonal System Solver

©McGraw-Hill Education.

You might also like