LA Slides 1 To 9
LA Slides 1 To 9
Osama Sohrab
National University Of Computer & Emergining Sciences, Peshawar
Spring 2025
Vitamin
Brand A B C
1 1 2 4
2 1 1 3
3 0 1 1
Vit A: 05 units
Vit B: 13 units
Vit C: 23 units
Let x be the number of pills from brand 1, y be the number of pills from brand 2 and z
be the number of pills from brand 3 which fulfill our requirement. Then we have
Vit A Eq : x + y + 0z = 5
Vit B Eq : 2x + y + z = 13
Vit C Eq : 4x + 3y + z = 23.
4 3 1 23
Performing the row operations:
R2 − 2R1 → R2 , R3 − 4R1 → R3 ,
we get:
1 1 0 5
0 −1 1 3
0 −1 1 3
Osama Sohrab Linear Algebra 6 / 186
Performing the row operation:
R3 − R2 → R3
We get:
1 1 0 5
0 −1 1 3
0 0 0 0
From R2 :
−y + z = 3 =⇒ z − 3 = y or y = z − 3 z is free
From R1 :
x + y = 5 =⇒ x = 5 − y
Substituting y = z − 3:
x = 5 − (z − 3) = 5 − z + 3 = 8 − z ⇒ x = 8 − z
Osama Sohrab Linear Algebra 7 / 186
Thus
x = 8 − z, y = z − 3, z is free.
x 8−z
y = z − 3 , z ∈ {3, 4, 5, 6, 7, 8}
z z
(b) For z = 3, we have:
x 5
y = 0
z 3
So, the least expensive treatment is:
Definition
A matrix is a rectangular array of numbers. The numbers in the array are called
the entries of the matrix.
The entry in row i and column j of a matrix A is also commonly denoted by the symbol
(A)ij . Thus, for matrix (1) above, we have:
(A)ij = aij
Osama Sohrab Linear Algebra 11 / 186
and for the matrix: " #
2 −3
A=
7 0
We have:
(A)11 = 2, (A)12 = −3, (A)21 = 7, and (A)22 = 0.
Row and column vectors are of special importance, and it is common practice to denote
them by boldface lowercase letters rather than capital letters. For such matrices, double
subscripting of the entries is unnecessary. Thus a general 1×n row vector a and a general
m × 1 column vector b would be written as:
b1
b2
h i
a = a1 a2 · · · an and b =
..
.
bm
A = B, B = C, A = C.
Solution
A = B is impossible because A and B are of different sizes: A is 2 × 2 whereas B is
2 × 3. Similarly, B = C is impossible. But A = C is possible provided that corresponding
entries are equal:
" # " #
a b 1 0
=
c d −1 2
means a = 1, b = 0, c = −1, and d = 2.
Osama Sohrab Linear Algebra 16 / 186
Matrices Addition & Subtraction
If A and B are matrices of the same size, then the sum A + B is the matrix
obtained by adding the entries of B to the corresponding entries of A, and the
difference A − B is the matrix obtained by subtracting the entries of B from
the corresponding entries of A. Matrices of different sizes cannot be added or
subtracted.
In matrix notation, if A = [aij ] and B = [bij ] have the same size, then:
(A + B)ij = (A)ij + (B)ij = aij + bij and (A − B)ij = (A)ij − (B)ij = aij − bij .
Then
−2 4 5 4 6 −2 −5 2
A + B = 1 2 2 3 , A − B = −3 −2 2 5 .
7 0 3 5 1 −4 11 −5
We have:
" # " # " #
4 6 8 0 −2 −7 1 3 −2 1
2A = , (−1)B = , C=
2 6 2 1 −3 5 3 1 0 4
" # 4 1 4 3 " #
1 2 4 □ □ □ □
0 −1 3 1 =
2 6 0 □ □ 26 □
2 7 5 2
(2 · 4) + (6 · 3) + (0 · 5) = 26
a11 a12 a13 a14 h i
A = a21 a22 a23 a24 = c1 c2 c3 c4
0 1 8 6 1
Solution The columns of B are
8 9
b1 = 7 and b2 = 2 ,
6 1
so
2 3 5 8 67
Ab1 = 1 4 7 7 = 78 ,
0 1 8 6 55
Osama Sohrab Linear Algebra 29 / 186
and
2 3 5 9 29
Ab2 = 1 4 7 2 = 24 .
0 1 8 1 10
Hence,
67 29
AB = [Ab1 Ab2 ] = 78 24 .
55 10
A0 = I and An = AA · · · A [n factors]
Because these definitions parallel those for real numbers, the usual laws of nonnegative
exponents hold; for example,
Assuming that the sizes of the matrices are such that the indicated operations can
be performed, the following rules of matrix arithmetic are valid:
(a) A + B = B + A [Commutative law for matrix addition]
(b) A + (B + C) = (A + B) + C [Associative law for matrix addition]
(c) A(BC) = (AB)C [Associative law for matrix multiplication]
(d) A(B + C) = AB + AC [Left distributive law]
(e) (B + C)A = BA + CA [Right distributive law]
(f ) A(B − C) = AB − AC
(g) (B − C)A = BA − CA
∴ AB ̸= BA
Here " #
3 4
AB = AC =
6 8
But
B ̸= C
We will denote a zero matrix by O unless it is important to specify its size, in which case
we will denote the m × n zero matrix by Om×n .
a11 a12 a13 a14
0 a22 a23 a24
0 0 a a
33 34
0 0 0 a44
The following matrices are symmetric since each is equal to its own transpose.
6 0 0 0
" # 1 4 5
7 −3 0 −4 0 0
, 4 −3 0 ,
−3 5 0 0 0 0
5 0 7
0 0 0 8
Matrices A and B are said to be row equivalent if either (hence each) can be
obtained from the other by a sequence of elementary row operations.
Listed below are two elementary matrices and the operations that produce them.
" # 1 0 3
1 0
0 1 0
0 −3
0 0 1
Multiply the second row of I2 by −3.
Add 3 times the third row of I3 to the first row.
Listed below are two elementary matrices and the operations that produce them.
1 0 0 0
" #
1 0 0 0
0 1
0 −3 0 0
1 0
0 1 0 0
Multiply the second row of I2 by −3. Interchange the second and fourth rows of I4 .
Symbol Meaning
Ri ↔ Rj Interchange rows i and j
kRi Multiply the ith row by the nonzero constant k
Ri + kRj Multiply the jth row by k and add to the ith row
det[a11 ] = a11
Let’s talk about minor and cofactor of an element of a matrix with the help of which we
will calculate determinants of higher order matrices.
If A is a square matrix, then the minor of entry Aij is denoted by Mij and is
defined to be the determinant of the submatrix that remains after the ith row and
jth column are deleted from A. The number (−1)i+j Mij is denoted by Cij and is
called the cofactor of entry aij .
and
det(A) = ai1 Ci1 + ai2 Ci2 + · · · + ain Cin
[cofactor expansion along the ith row]
5 4 −2
Solution
By cofactor expansion along the first row:
3 1 0
−4 3 −2 3 −2 −4
det(A) = −2 −4 3 =3 −1 +0
4 −2 5 −2 5 4
5 4 −2
= 3(−4) − 1(−11) + 0 = −1
Osama Sohrab Linear Algebra 57 / 186
By cofactor expansion along the first column
3 1 0
−4 3 1 0 1 0
det(A) = −2 −4 3 =3 − (−2) +5
4 −2 4 −2 −4 3
5 4 −2
The best strategy for cofactor expansion is to expand along a row or column with
the most zeros.
In the 2 × 2 case, the determinant can be computed by forming the product of the entries
on the rightward arrow and subtracting the product of the entries on the leftward arrow.
In the 3 × 3 case we first recopy the first and second columns as shown in the figure,
after which we can compute the determinant by summing the products of the entries on
the rightward arrows and subtracting the products on the leftward arrows.
For example
1 0 3
0 0
= 0, 4 0 5 =0
1 2
6 0 7
Observe that
" #
1 2 1 3
det(A) = = −2, det(AT ) = = −2
3 4 2 4
Each of the following matrices has two proportional rows or columns; thus, each has a
determinant of zero.
3 −1−5 4
" # 1 −2 7
−1 4 6 −2 5 2
, −4 8 5 ,
−2 8 5 8 1 4
2 −4 3
−9 3 −12 15
det(kA) = k n det(A)
where a11 , a22 , . . . , ann are the entries on the main diagonal of A.
3 0 0 0
−3 0 0
2 6 0 0
= 3(6)(−4)(−2) = 144, 0 6 0 = (−3)(6)(4) = −72.
5 9 −4 0
0 0 4
7 2 4 −2
For example,
1 7 5 1 7 5 1 7 5
det 2 0 3 = det 2 0 3 + det 2 0 3 .
1 + 0 4 + 1 7 + (−1) 1 4 7 0 1 −1
Osama Sohrab Linear Algebra 69 / 186
In general,
det(A + B) ̸= det(A) + det(B)
Consider
" # " # " #
1 2 3 1 4 3
A= , B= , A+B = .
2 5 1 3 3 8
We have det(A) = 1, det(B) = 8, and det(A + B) = 23; thus
The idea of the method is to reduce the given matrix to upper triangular form by
elementary row operations, then compute the determinant of the upper triangular matrix
(an easy computation), and then relate that determinant to that of the original matrix.
2 6 1
Solution
0 1 5
det(A) = 3 −6 9
2 6 1
3 −6 9
= − 0 1 5 R1 ↔ R2
2 6 1
0 0 0 25 0 0 1 3
are in echelon form. In fact, the second matrix is in reduced echelon form.
is called the matrix of cofactors from A. The transpose of this matrix is called
the adjoint of A and is denoted by adj(A).
2 −4 0
then
C11 = 12 C12 = 6 C13 = −16
C21 = 4 C22 = 2 C23 = 16
C31 = 12 C32 = −10 C33 = 16
12 −10 16
−16 16 16
AB = BA = I,
If A is invertible, then
1
A−1 = adj(A)
det(A)
Solution:
The determinant of A is
2 −4 0
Solution
−16 16 16
Osama Sohrab Linear Algebra 89 / 186
The inverse of A is
12 4 12
12 4 12 64 64 64
1 1
A−1 =
6 2 10
adj(A) = 6 2 −10 = − 64 .
64 64
det(A) 64
−16 16 16 − 16
64
16
64
16
64
Another method for finding the inverse of a matrix is illustrated in the coming slides.
1 0 8
Solution
1 2 3 1 0 0
2 5 3 0 1 0
1 0 8 0 0 1
1 2 3 1 0 0
0 1 −3 −2 1 0 R2 − 2R1 & R3 − R1
0 −2 5 −1 0 1
Osama Sohrab Linear Algebra 93 / 186
1 2 3 1 0 0
0 1 −3 −2 1 0 R3 + 2R2
0 0 −1 −5 2 1
1 2 3 1 0 0
0 1 −3 −2 1 0 −R3
0 0 1 5 −2 −1
1 2 0 −14 6 3
0 1 0 13 −5 −3 R1 − 3R3 & R2 + 3R3
0 0 1 5 −2 −1
0 0 1 5 −2 −1
Thus
−40 16 9
A−1 = 13 −5 −3
5 −2 −1
−1 2 5
The computations are as follows:
1 6 4 1 0 0
2 4 −1 0 1 0
−1 2 5 0 0 1
1 6 4 1 0 0
0 −8 −9 −2 1 0 R2 − 2R1 & R3 + R1
0 8 9 1 0 1
Osama Sohrab Linear Algebra 97 / 186
1 6 4 1 0 0
0 −8 −9 −2 1 0 R3 + R2
0 0 0 −1 1 1
Since we have obtained a row of zeros on the left side, A is not invertible.
4 −3 8
0 0 2
then
1 0 0 1 0 0 1 0 0
A−1 = 0 − 13 0 , 5
A = 0 −243 0 , A−5 1
= 0 − 243 0.
0 0 12 0 0 32 0 0 1
32
det A ̸= 0
x + 2y + z = 0
x + 3y + 6z = 0
2x + 3y + az = 0
0 1 −5 8
where a′ s are not all zero. If b = 0 in the above equation then we have
a1 x1 + a2 x2 + . . . + an xn = 0
For example,
2x + 3y = 4
5x + 6y = 7
or,
5p + 2q − 3r = 4
5p + 6q + 7r = 8
9p − 4q + 2r = 3
Osama Sohrab Linear Algebra 109 / 186
A general linear system of m equations in the n unknowns x1 , x2 , . . . , xn can be written
as
a11 x1 + a12 x2 + · · · + a1n xn = b1
a21 x1 + a22 x2 + · · · + a2n xn = b2
.. .. .. .. (⋆)
. . . .
am1 x1 + am2 x2 + · · · + amn xn = bm
x1 = s 1 , x2 = s2 , . . . , xn = sn
5x + y = 3
2x − y = 4
a1 x + b 1 y = c 1
a1 x + b 1 y = c 2
in which the graphs of the equations are lines in the xy-plane. There are three possibilities.
Osama Sohrab Linear Algebra 112 / 186
Osama Sohrab Linear Algebra 113 / 186
For a linear system with three equations and three variables, each equation in the system
represents a plane in 3D-space.
Let
a11 a12 · · · a1n a11 a12 · · · a1n b1
a21 a22 · · · a2n a21 a22 · · · a2n b2
A=
.. .. .. ,
.. Ã = [A | b] =
.. .. .. .. ..
. . . . . . . . .
am1 am2 · · · amn am1 am2 · · · amn bm
Every homogeneous linear system is consistent because all such systems have x1 =
0, x2 = 0, · · · , xn = 0 as a solution. This solution is called the trivial solution; if
thereare other solutions, they are called nontrivial solutions.
is consistent, that is, has solution(s), if and only if the coefficient matrix A and the
augmented matrix à = [A|b] have the same rank.
(b) Uniqueness: The system (⋆) has precisely one solution if and only if this common
rank r of A and equals n.
r1 = r2 r1 ̸= r2
Consistent Inconsistent
r1 = r2 = n r1 = r2 < n
8x + 5y + 11z = 30
−x − 4y + 2z = 3
2x − y + 5z = 12
x + ay + cz = 0
bx + cy − 3z = 1
ax + 2y + bz = 5
1 2 −1 0 2
0 1
1 −2 −3
R3 − 2R1 & R4 − R1
0 0
3 −3 −6
0 −6 −6 −1 −21
1 2 −1 0 2
0 1 1 −2 −3 1 1
R3 & − R4
0 0
1 −1 −2
3 13
0 0 0 1 3
x3 − x4 = −2
⇒ x3 = −2 + x4
⇒ x3 = −2 + 3
⇒ x3 = 1
From R2 we have
x2 + x3 − 2x4 = −3
⇒ x2 = −3 − x3 + 2x4
⇒ x2 = −3 − 1 + 6
⇒ x2 = 2
Osama Sohrab Linear Algebra 129 / 186
Similarly from R1 we have
x1 + 2x2 − x3 = 2
⇒ x1 = 2 − 2x2 + x3
⇒ x1 = 2 − 4 + 1
⇒ x1 = −1
Thus
x1 −1
x2 2
=
x 1
3
x4 3
x − 2y + 3z = 9
−x + 3y = −4
2x − 5y + 5z = 17
Solution
The augmented matrix for this system is
1 −2 3 9
−1 3 0 −4
2 −5 5 17
0 −1 −1 −1
1 −2 3 9
0 1 3 5 R3 + R2
0 0 2 4
1 −2 3 9
1
0 1 3 5 R3
2
0 0 1 2
0 0 1 2
1 0 0 1
0 1 0 −1 R1 − 9R3 & R2 − 3R3
0 0 1 2
x3 2
Osama Sohrab Linear Algebra 134 / 186
Problem
Use Gauss-Jordan elimination to solve the system.
Solution
The RREF of the augmented matrix is
m=n m ̸= n
Gauss-Jordan Elimination
where the ith column of Ai is the column of constants in the system of equations.
−x + 2y − 3z = 1
2x +z =0
3x − 4y + 4z = 2
Solution
The determinant of the coefficient matrix is
−1 2 −3
|A| = 2 0 1 = 10.
3 −4 4
1 2 −3
0 0 1
2 −4 4 (1)(−1)5|2 − 4| (1)(−1)(−8) 4
x= = = =
10 10 10 5
x1 + 2x2 + 3x3 = 5
2x1 + 5x2 + 3x3 = 3
x1 + 8x3 = 17
1 0 8 x3 17
−40 16 9
A−1 = 13 −5 −3
5−2 −1
−40 16 9 5 1
−1
x = A b = 13 −5 −3 3 = −1
5 −2 −1 17 2
or x1 = 1, x2 = −1, x3 = 2.
Osama Sohrab Linear Algebra 142 / 186
A network is a set of branches through which something “flows.” For example, the
branches might be electrical wires through which electricity flows, pipes through which
water or oil flows, traffic lanes through which vehicular traffic flows, or economic linkages
through which money flows. A point where two or more branches meet is called a node
or a junction.
A
A & B are junctions
D
35 55
B
15
60
Figure 3: A, B, C, and D are junctions.
I2
I1
I3
Figure 4: I1 = I2 + I3
At A 500 = f1 + f2 + f3
At B f1 + f4 + f6 = 400
At C f3 + f5 = f6 + 100
At D f2 = f4 + f5
f1 + f2 + f3 = 500
f1 + f4 + f6 = 400
f3 + f5 − f6 = 100
f2 − f4 − f5 = 0
f1 = 400 − f4 − f6
f2 = f4 + f5
f3 = 100 − f5 + f6
Thus
f1 400 − f4 − f6
f2 f4 + f5
f 100 − f + f
3 5 6
=
f4 f4
f f
5 5
f6 f6
Osama Sohrab Linear Algebra 150 / 186
Of course, not all these solutions may be acceptable in the real situation. For example,
the flows f1 , f2 , · · · , f6 are all positive in the present context. This imposes constraints
on the flows: f1 ≥ 0 and f3 ≥ 0 which becomes
f4 + f6 ≤ 400
f5 − f6 ≤ 100
by which we mean that one methane molecule combines with two stable oxygen molecules
to produce one carbon dioxide molecule and two water molecules.
CH4 + O2 −→ CO2 + H2 O
The standard convention is to use the smallest positive integers that will balance the
equation. To balance this equation we must find positive integers x1 , x2 , x3 and x4 such
that
x1 (CH4 ) + x2 (O2 ) −→ x3 (CO2 ) + x4 (H2 O)
For each of the atoms in the equation, the number of atoms on the left must be equal
to the number of atoms on the right. Expressing this in tabular form we have
x1 − x3 = 0
4x1 − 2x4 = 0
2x2 − 2x3 − x4 = 0
0 2 −2 −1 0
0 0 1 − 12 0
from which we conclude that the general solution of the system is
1 1
x1 = x4 , x2 = x4 , x3 = x4
2 2
Osama Sohrab Linear Algebra 156 / 186
where x4 is arbitrary. The smallest positive integer values for the unknowns occur when
we let x4 = 2, so the equation can be balanced by letting x1 = 1, x2 = 2, x3 = 1,
x4 = 2.
(b)
C6 H12 O6 → CO2 + C2 H5 OH [fermentation of sugar]
y = ax + b (3)
whose graph passes through two known distinct points, (x1 , y1 ) and (x2 , y2), in the xy-
plane. You have probably encountered various methods in analytic geometry for finding
the equation of a line through two points, but here we will give a method based on linear
systems that can be adapted to general polynomial interpolation.
ax1 + b = y1
ax2 + b = y2
Solving the linear system we can obtain a and b and then by putting these value in (3)
we can get the equation of line.
Given any n points in the xy-plane that have distinct x-coordinates, there is a
unique polynomial of degree n − 1 or less whose graph passes through those points.
30 101 18 17
a0 = 1, a1 = −
, a2 = , a3 = , a4 = −
24 24 24 24
which means the polynomial function is
30 101 2 18 3 17 4
p(x) = 1 − x+ x + x − x
24 24 24 24
1
= (24 − 30x + 101x2 + 18x3 − 17x4 ).
24
x2 + xy − y 2 = 1
2x2 − xy + 3y 2 = 13
x2 + 3xy + 2y 2 = 0
[Hint: These equations are linear in the new variables x1 = x2 , x2 = xy, and x3 = y 2 .]
Figure 5
Osama Sohrab Linear Algebra 168 / 186
We use the notation Pi → Pj (which is read ”Pi is connected to Pj ”) to indicate that
the directed edge (Pi , Pj ) belongs to the directed graph. Geometrically, we can visualize
a directed graph by representing the vertices as points in the plane and representing the
directed edge Pi → Pj by drawing a line or arc from vertex Pi to vertex Pj , with an arrow
pointing from Pi to Pj . If both Pi → Pj and Pj → Pi hold (denoted Pi ↔ Pj ), we draw
a single line between Pi and Pj with two oppositely pointing arrows (as with P2 and P3
in the Figure 5).
A directed graph may have separate “components” of vertices that are connected only
among themselves; and some vertices, such as P5 , may not be connected with any other
vertex. Also, because Pi → Pi is not permitted in a directed graph, a vertex cannot be
connected with itself by a single arc that does not pass through any other vertex.
Figure 7
Osama Sohrab Linear Algebra 172 / 186
Influences Within a Family
A certain family consists of a mother, father, daughter, and two sons. The family members
have influence, or power, over each other in the following ways: the mother can influence
the daughter and the oldest son; the father can influence the two sons; the daughter can
influence the father; the oldest son can influence the youngest son; and the youngest son
can influence the mother. We may model this family influence pattern with a directed
graph whose vertices are the five family members. If family member A influences family
member B , we write A → B. Figure 174 is the resulting directed graph, where we have
used obvious letter designations for the five family members. The vertex matrix of this
directed graph is
The father cannot directly influence the mother; that is, F → M is not true. But he
can influence the youngest son, who can then influence the mother. We write this as
F → Y S → M and call it a 2-step connection from F to M . Analogously, we call
M → D a 1-step connection, F → OS → Y S → M a 3-step connection, and so
forth.
Osama Sohrab Linear Algebra 174 / 186
Theorem
(r)
Let M be the vertex matrix of a directed graph and let mij be the (i, j)-th element
(r)
of M r . Then mij is equal to the number of r-step connections from Pi to Pj .
Figure 9
Also,
2 0 1 1 1 3 3 1
1 1 1 1 2 2 3 1
M2 =
0
, and M 3 =
2 2 0
4
0 2 2
2 0 1 1 1 3 3 1
Let V = Rn , and define the vector space operations on V to be the usual operations of
addition and scalar multiplication of n-tuples; that is,
The set V = Rn is closed under addition and scalar multiplication because the foregoing
operations produce n-tuples as their end result, and these operations satisfy Axioms 2, 3,
4, 5, 7, 8, 9, and 10.