Lecture 2 - Algebra - BMSLec01
Lecture 2 - Algebra - BMSLec01
Lecture 2 - Algebra - BMSLec01
Contents
1 Linear System of Equations 2
2 Matrices 3
2.1 Transpose of a Matrix . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Symmetric Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.3 Diagonal Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.4 Identity Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.5 Upper Triangular Matrix . . . . . . . . . . . . . . . . . . . . . . 5
2.6 Lower Triangular Matrix . . . . . . . . . . . . . . . . . . . . . . . 5
2.7 Banded Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3 Matrix Operations 6
3.1 Addition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.2 Subtraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.3 Multiplication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.4 Determinant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.5 Inverse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
5 Questions 14
1
1 Linear System of Equations
Consider the following linear system of equations
where, the a’s are constant coefficients, the b’s are constants, and n is the number
of equations. The above equation can be written in matrix form as follows
Ax = b (2)
where
a11 ... a1n x1 b1
a21 ... a2n x2 b2
A= x = b = (3)
.. .. .. .. ..
. . . . .
an1 ... ann xn bn
Example 1. Convert the following linear system of equations into matrix form.
x1 + 2x2 + x3 = 2
x1 − x2 + 2x3 = 5 (4)
2x1 + 2x2 + 2x3 = 12
Solution: The linear system of equations in (4) can be written in matrix form
as follows
Ax = b
where
1 2 1 x1 2
A= 1 −1 2 x = x2 b = 5 (5)
2 2 2 x3 12
There are several methods to solve linear system of equations similar to those
shown in (4). Such as
• Algebraic method. Done by hand, becomes harder with the number of
variables.
• Graphical method. Nearly impossible for number of variables n > 3.
• Matrix inverse method. Computationally very intense when the matrix
size becomes large.
• Cramer’s method. Computationally very intense when the matrix size
becomes large.
2
• Gaussian elimination. Better than all previous methods in terms of com-
putation.
• Gaussian elimination with pivoting. Makes Gaussian elimination method
more stable.
• Gaussian elimination with scaling. Makes Gaussian elimination method
more stable.
2 Matrices
A matrix A is a two dimensional array. The (i, j)th element of the matrix A is
denoted as aij . Horizontal set of matrix elements are called a row and vertical
set is called a column. A matrix with n rows and m columns is said to have a
dimension of n by m or (n × m).
B = AT (6)
Exercise 1.
Write the transpose of
7 3 1 6
A= 3 9 4 5 (8)
1 4 10 2
Solution.
7 3 1
T
3 9 4
B=A =
1
(9)
4 10
6 5 2
3
Exercise 2 (Symmetric matrix). A 4 by 4 matrix (referred hereafter as 4 × 4
matrix) is A is given below
7 3 1 6
3 9 4 5
A=
1 4 10
(11)
2
6 5 2 8
Solution.
7 3 1 6
3 9 4 5
B = AT =
1
(12)
4 10 2
6 5 2 8
aij = 0 ∀i 6= j (13)
4
2.5 Upper Triangular Matrix
An upper triangular matrix is one where all the elements below the main
diagonal are zero, i.e.,
5
Example 7. (A 6 × 6 penta-diagonal matrix)
7 3 5 0 0 0
6 2 3 9 0 0
9 2 7 4 9 0
A= 0 7 1 6 2
(23)
8
0 0 6 4 9 2
0 0 0 2 2 8
3 Matrix Operations
3.1 Addition
Addition of two matrices say A and B of equal size is accomplished by adding
corresponding terms in each matrix, i.e.,
3.2 Subtraction
Subtraction of one matrix (B) from another (A) of equal size is accomplished
by subtracting corresponding terms in each matrix, i.e.,
3.3 Multiplication
Multiplication of two matrices can be performed only if the first matrix has as
many columns as the number of rows in the second matrix. Product of an m × n
matrix A and and n × k matrix B is represented as
n
X
C = A ∗ B =⇒ cij = aik ∗ bkj (26)
k=1
3.4 Determinant
For a 2 × 2 matrix A, the determinant D is defined as follows
a11 a12
D= = a11 a22 − a21 a12 (27)
a21 a22
6
For an n × n matrix A, the determinant D is defined as follows
n
X
D = |A| = (−1)(j+1) |Mj | a1j (28)
j=1
where |Mj | denotes the determinant of the minor of A at the j th column. The
minor of A at the j th column is a new matrix formed by removing the first row
and the j th column of the matrix A.
where
a22 a23
M1 =
a32 a33
a21 a23
M2 = (31)
a31 a33
a21 a22
M3 =
a31 a32
3.5 Inverse
If a matrix A is non-singular and square, then its inverse A−1 satisfies the
following
7
where |A| is the determinant of A and C is the matrix of cofactors. The (i, j)th
element of C is written as
where the matrix Mij (known as the minor) is formed by removing the ith row
and the j th column of the matrix A.
Example 8 (Inverse of a 2 × 2 matrix). Given that
a11 a12
A= (35)
a21 a22
Solution.
All we have to do is plot the two equations separately and find the coordi-
nates of the intersection. Fig. 1 shows the lines represented by equations (38)
and (39) above. We can see that the lines intersect at (4, 3), hence the solution
to the above linear system of equations is x1 = 4 and x2 = 3.
8
Figure 1: Graphical solution of two linear equations. The coordinates of
their intersection represent the solution of the equations.
Ax = b (40)
The Cramer’s method showed that the ith element of x can be obtained as
|Bi |
xi = (41)
|A|
9
Exercise 7. Consider the following system of equations
Ax = b (42)
where it is given that A is 3 × 3. Use Cramer’s method to find the solution for
x.
Solution.
Let us denote the elements of A as aij where i, j ∈ 1, 2, 3.
b1 a12 a13
b2 a22 a23
b3 a32 a33
x1 = (43)
|A|
a11 b1 a13
a21 b2 a23
a31 b3 a33
x2 = (44)
|A|
a11 a12 b1
a21 a22 b2
a31 a32 b3
x3 = (45)
|A|
Exercise 8. Let us solve the following system of equations using Cramer’s
method
3x1 + 2x2 = 18 (46)
−x1 + 2x2 = 2 (47)
Solution.
First, let us write the system of equations in the matrix form Ax = b, i.e.,
3 2 x1 18
= (48)
−1 2 x2 2
Next, let us find out the determinant of A
3 2
D= = 3 ∗ 2 − (−1) ∗ 2 = 8 (49)
−1 2
Now, we can use Cramer’s method to write the solutions as follows
18 2
2 2 18 ∗ 2 − 2 ∗ 2
x1 = = =4
D 8 (50)
3 18
−1 2 3 ∗ 2 − (−1) ∗ 18
x2 = = =3
D 8
10
4.3 Matrix Inverse Method
Let us write the general linear system of equations in matrix form
Ax = b (51)
Exercise 9. Let us solve the following system of equations using inverse method
Solution.
First, let us write the system of equations in the matrix form Ax = b, i.e.,
3 2 x1 18
= (55)
−1 2 x2 2
x = A−1 b
2/8 −2/8 18
=
1/8 3/8 2 (57)
4
=
3
11
• Back substitution. Once we have a system that is in the upper diagonal
form, it is easy to solve for x using back substitution.
The above two steps are achieved through row operations. The row operations
consists of the following that does not alter the solution of the system:
12
4.5 Procedure
Consider the folllowing linear system of equations
and so on.
In general
(i−2) Pn (i−1)
bi−1 − j=i+1 aij xj
xi = (i−1)
(62)
aii
13
Example:
Let us solve the following system of equation using Gaussian elimination
x1 + x2 − x3 = −3 ... (r1 )
6x1 + 2x2 + 2x3 = 2 ... (r2 ) (63)
−3x1 + 4x2 + x3 = 1 ... (r3 )
x1 + x2 − x3 = −3 ... (r1 )
−4x2 + 8x3 = 20 ... (r2 ) (64)
7x2 + −2x3 = −8 ... (r3 )
r2 ← r2 /(−4)
r3 ← r3 − 7 ∗ r1
x1 + x2 − x3 = −3 ... (r1 )
x2 − 2x3 = −5 ... (r2 ) (65)
+12x3 = 27 ... (r3 )
x1 + x2 − x3 = −3
x2 − 2x3 = −5 (66)
x3 = 2.25
• Back substitution
x2 = −5 + 2x3 = −5 + 2 ∗ 2.25 = −0.5
x1 = −3 − x2 + x3 = −3 − (−0.5) + 2.25 = −0.25
5 Questions
Question 1 (Matrices).
14
Answer the following questions based on the matrices given below.
4 7 4 3 7 3
A= 1 2 B= 1 2 7 C= 6
5 6 2 0 4 1
1 5 8
3 2 3 0 1
D= E= 0 2 3 F=
−1 2 1 7 3
0 0 6
1 0 0
G= 7 6 4 H= 5 2 0
8 6 3
Question 2.
Answer the following questions based on the matrices given below.
4 −2 1 4 3 1
A= 1 2 0 B= 1 2 0 (67)
−3 1 1 2 0 4
3
3 2
C= 6 D= (68)
−1 2
1
15
(b) Someone tells you that
1/2 −3/4 −1/8
B−1 = −1/4 7/8 5/80 (69)
−1/4 3/8 5/16
Verify if it is true.
6x3 + 2x2 = 8
2 − x1 = x3 (70)
5x2 + 8x1 = 13
3x − y = 7
(71)
x+y =9
2x1 − x2 + 4x3 = 12
x1 + x2 + 2x3 = 6 (72)
4x1 + x2 − 2x3 = 0
(a) Write the row operations in the same orders in which they were applied
(b) Write the resulting system in the following form Ax = b where A is an
upper diagonal matrix
(c) Write the obtained solutions for x3 , x2 and x1 through back-substitution.
16
Question 6 (Linear System of Equations).
Consider the set of equations
2x2 + 5x3 = 9
2x1 + x2 + x3 = 9 (73)
3x1 + x2 = 10
3x − y = 1
(74)
x+y = 3
x1 + x2 − x3 = −3
6x1 + 2x2 + 2x3 = 2 (75)
−3x1 + 4x2 + x3 = 1
17
(a) Write the row operations in the same orders in which they were applied
(b) Write the resulting system in the following form Ax = b where A is an
upper diagonal matrix
(c) Write the obtained solutions for x1 , x2 and x3
Question 10 (Naive Gaussian Elimination).
Question 11.
Use Gaussian elimination to solve the following system of equations for the
x’s showing all the steps involved.
2x1 − x2 + 4x3 = 7
x1 + x2 + 2x3 = 5 (78)
4x1 + x2 − 2x3 = −3
(a) Write the row operations in the same orders in which they were applied
(b) Write the resulting system in the following form Ax = b where A is an
upper diagonal matrix
(c) Write the obtained solutions for x3 , x2 and x1 through back-substitution.
References
[1] G. Strang, Introduction to linear algebra. Wellesley-Cambridge Press Welles-
ley, MA, 2016.
18