Combinepdf
Combinepdf
3.5.1 Lab 6
4 7 6
⎡ ⎤
J = ⎢ −2 −2 −1 ⎥
⎣ ⎦
4 4 1
J = [4 7 6 ; -2 -2 -1 ; 4 4 1 ] ;
4 7 6
⎡ ⎤
M = ⎢ −2 −2 −1 ⎥
⎣ ⎦
4 4 1
M = [4 7 6 ; -2 -2 -1 ; 4 4 1 ] ;
4 7 6
⎡ ⎤
S = ⎢ −2 −2 −1 ⎥
⎣ ⎦
4 4 1
S = [4 7 6 ; -2 -2 -1 ; 4 4 1 ] ;
A through D, do A ∗ B.
D through J, do D ∗ E.
J through Z, do J ∗ K .
−1 −2 −2
⎡ ⎤
0 8 1 5 ⎢ 7 4 0⎥
A = [ ] and B = ⎢ ⎥
3 1 8 −2 ⎢ 0 −2 5⎥
⎣ ⎦
0 −2 3
A = [0 8 1 5 ; 3 1 8 -2 ];
B = [-1 -2 -2 ; 7 4 0 ; 0 -2 5 ; 0 -2 3 ];
https://straightdraw.github.io/Linear/ch3/05/1.html 1/3
3/4/24, 8:40 PM 3.5.1 Lab 6 — Linear Algebra with MATLAB
−1 −2 −2
⎡ ⎤
−2 1 −1 −2 ⎢ 7 4 0⎥
D = [ ] and E = ⎢ ⎥
7 3 −2 6 ⎢ 0 −2 5⎥
⎣ ⎦
0 −2 3
D = [-2 1 -1 -2 ; 7 3 -2 6 ];
E = [-1 -2 -2 ; 7 4 0 ; 0 -2 5 ; 0 -2 3 ];
2 0
⎡ ⎤
−2 −1 1 −2 ⎢ 3 −1 ⎥
J = [ ] and K = ⎢ ⎥
−1 −2 7 0 ⎢ 3 6 ⎥
⎣ ⎦
8 2
J = [-2 -1 1 -2 ; -1 -2 7 0 ];
K = [2 0 ; 3 -1 ; 3 6 ; 8 2 ];
B through G, do B.
H through Q, do H.
R through Z, do R.
A pick any of the three.
6 −8 −5
⎡ ⎤
B = ⎢ 6 −7 −3 ⎥
⎣ ⎦
3 −4 −2
−3 −3 13 Print to PDF
⎡ ⎤
H = ⎢ −1 −2 3⎥
⎣ ⎦
1 2 −5
1 0 −8
⎡ ⎤
R = ⎢ −2 0 19 ⎥
⎣ ⎦
−2 −2 11
https://straightdraw.github.io/Linear/ch3/05/1.html 2/3
3/4/24, 8:40 PM 3.5.1 Lab 6 — Linear Algebra with MATLAB
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch3/05/1.html 3/3
3/4/24, 8:40 PM 3.6 Invertible Matrix Theorem — Linear Algebra with MATLAB
1. A is invertible.
2. A has n pivots.
3. Null(A) = 0
⃗
.
4. The columns of A are linearly independent.
5. The columns of A span Rn .
6. Ax⃗ = b
⃗
has a unique solution for each b in Rn .
7. The linear transformation T is invertible, specifically:
T is one-to-one.
T is onto.
Examples
Example 1
Determine if the linear transformation T is one-to-one. Is it onto? The standard matrix associated with T is
0 −2 −3 9
⎡ ⎤
⎢ 0 0 0 1⎥
A = ⎢ ⎥
⎢ −2 2 5 −15 ⎥
⎣ ⎦
1 −1 −2 7
A = [0 -2 -3 9 ; 0 0 0 1 ; -2 2 5 -15 ; 1 -1 -2 7 ];
rref(A)
ans =
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
With 4 pivots, we know the dimension of the null is zero and thus that the transformation is both one-to-one and
onto (invertible).
Example 2
Is the set of vectors a basis for R5 ?
⎧ 1 2 −2 2 2
⎪ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤⎫⎪
⎪
⎪ ⎪
⎪
⎪ ⎪
⎪
⎪ ⎢ −2 ⎥ ⎢ 0 ⎥ ⎢ −1 ⎥ ⎢ 1 ⎥ ⎢ 0 ⎥⎪⎪
⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥
⃗
⎨v1 = ⎢ 2 ⎥ , v2
⃗ = ⎢ 5 ⎥ , v⃗ = ⎢
3 3 ⎥ , v4
⃗ = ⎢ 2 ⎥ , v⃗
5 = ⎢ 3 ⎥⎬
⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥
⎪ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥⎪
⎪
⎪ ⎢ −1 ⎥ ⎢ 4 ⎥ ⎢ 3⎥ ⎢ 4 ⎥ ⎢ 1 ⎥⎪⎪
⎪
⎪
⎩
⎪
⎪
⎭
Print to PDF
⎪ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦⎪
3 5 4 3 2
https://straightdraw.github.io/Linear/ch3/6.html 1/2
3/4/24, 8:40 PM 3.6 Invertible Matrix Theorem — Linear Algebra with MATLAB
B = [1 2 -2 2 2 ; -2 0 -1 1 0 ; 2 5 3 2 3 ; -1 4 3 4 1 ; 3 5 4 3 2 ];
inv(B)
ans =
Since B is invertible, we know the columns are linearly independent and thus form a basis for R5 .
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch3/6.html 2/2
3/4/24, 8:43 PM 5.1 Eigenvalues and Eigenvectors — Linear Algebra with MATLAB
Example 1
Determine if the vector v ⃗ is an eigenvector of the matrix A where
15 0 24
⎡ ⎤
A = ⎢ 9 2 18 ⎥
⎣ ⎦
−8 0 −13
and
2
⎡ ⎤
v⃗ = ⎢ 3⎥
⎣ ⎦
−1
Solution. The question is whether the product Av ⃗ is equal to a scalar multiple of v ⃗, so we should just multiply and
check.
A = [15 0 24 ; 9 2 18 ; -8 0 -13 ];
v = [ 2 ; 3 ; -1 ]
v =
2
3
-1
A * v
ans =
6
6
-3
Example 2
Determine if the vector y ⃗ is an eigenvector of the matrix A where
−4 16 −14 22
⎡ ⎤
⎢ −6 20 −12 24 ⎥
B = ⎢ ⎥
⎢ 3 −8 9 −11 ⎥
⎣ ⎦
4 −12 8 −14
and
https://straightdraw.github.io/Linear/ch5/1.html 1/3
3/4/24, 8:43 PM 5.1 Eigenvalues and Eigenvectors — Linear Algebra with MATLAB
0
⎡ ⎤
⎢ −1 ⎥
y⃗ = ⎢ ⎥
⎢ 0⎥
⎣ ⎦
1
y =
1
-1
0
1
B*y
ans =
2
-2
0
2
Finding eignevalues
The eignevalues of a matrix A are possible values λ such that
Av ⃗ = λ v ⃗
Av ⃗ = λv ⃗
⃗
⟺ Av ⃗ − λ v ⃗ = 0
⃗
⟺ Av ⃗ − λI v ⃗ = 0
⃗
⟺ (A − λI )v ⃗ = 0
A − λI
and finding whether its null space has any nonzero vectors in it.
Example
Determine if λ = 3 is an eigenvalue for the matrix A where
A =
A = [3 0 0 ; -1 -13 15 ; -1 -12 14 ];
a = A - 3*eye(3)
a =
0 0 0
-1 -16 15
-1 -12 11
https://straightdraw.github.io/Linear/ch5/1.html 2/3
3/4/24, 8:43 PM 5.1 Eigenvalues and Eigenvectors — Linear Algebra with MATLAB
rref([a,zeros(3,1)])
ans =
1 0 1 0
0 1 -1 0
0 0 0 0
Because the homogeneous system is consistent, we know there are non-trivial solutions which means there are
non-zero vectors in the null space of A − λI . Thus, λ = 3 is an eigenvalue.
Example 3
To determine the associated eigenvector(s) once we know an eigenvalue, we write the solutions to the
homogeneous system in vector form.
x1 = −x3 −1
⎡ ⎤
x2 = x3 ⟹ v⃗ = ⎢ 1⎥
⎣ ⎦
x3 is free 1
The vector v ⃗ is an eigenvector of A associated with the eigenvalue λ = 3 , which can be verified by multiplication.
v = [ -1 ; 1 ; 1 ]
v =
-1
1
1
A * v
ans =
-3
3
3
A * v == 3 * v
ans =
1
1
1
Because equality holds (all 1’s in array), we know that we have found a eigenvalue-eigenvector pair.
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch5/1.html 3/3
3/4/24, 8:43 PM 5.2 The Characteristic Polynomial — Linear Algebra with MATLAB
p(λ) = det (A − λI )
Section 1
Finding eignevalues
The eignevalues of a matrix A are possible values λ such that
Av ⃗ = λ v ⃗
Av ⃗ = λv ⃗
⃗
⟺ Av ⃗ − λ v ⃗ = 0
⃗
⟺ Av ⃗ − λI v ⃗ = 0
⃗
⟺ (A − λI )v ⃗ = 0
3 0 0
⎡ ⎤
A = ⎢ 2 15 −14 ⎥
⎣ ⎦
2 12 −11
3 0 0 1 0 0
⎛⎡ ⎤ ⎡ ⎤⎞
3 0 0 λ 0 0
⎛⎡ ⎤ ⎡ ⎤⎞
= det ⎜⎢ 2 15 −14 ⎥ − ⎢ 0 λ 0 ⎥⎟
⎝⎣ ⎦ ⎣ ⎦⎠
2 12 −11 0 0 λ
3 − λ 0 0
⎛⎡ ⎤⎞
= det ⎜⎢ 2 15 − λ −14 ⎥ ⎟
⎝⎣ ⎦⎠
2 12 −11 − λ
We can expand across the top row which has two zero’s in it.
15 − λ −14
det(A − λI ) = (3 − λ) det ([ ]) − (0) + (0)
12 −11 − λ
Since the
https://straightdraw.github.io/Linear/ch5/2.html 1/9
3/4/24, 8:43 PM 5.2 The Characteristic Polynomial — Linear Algebra with MATLAB
15 − λ −14
det ([ ]) = (15 − λ)(−11 − λ) − (12)(−14)
12 −11 − λ
2
= λ + 11λ − 15λ − 165 + 168
2
= λ − 4λ + 3
2
p(λ) = (3 − λ)(λ − 4λ + 3)
3 2 2
= −λ + 4λ − 3λ + 3λ − 12λ + 9
3 2
= −λ + 7λ − 15λ + 9
A = [3 0 0 ; 2 15 -14 ; 2 12 -11 ];
charpoly(A)
ans =
1 -7 15 -9
2
p(λ) = (3 − λ)(λ − 4λ + 3)
2
= −(λ − 3) (λ − 1)
2
−(λ − 3) (λ − 1) = 0
λ = 3 and λ = 1
The multiplicity of the root λ = 3 is two. Eigenvalues also have multiplicties which match the multiplicities of
their corresponding roots. Since the multiplicity of the λ = 3 eigenvalue is two, we expect two different
eigenvectors to be associated with it.
As shown in section 1, to find an eigenvector related to λ = 1 , we must find the solutions (in vector form) to the
homogeneous system of equations:
A − λI = 0
Substituting λ = 1 :
A − I = 0
A - eye(3)
https://straightdraw.github.io/Linear/ch5/2.html 2/9
3/4/24, 8:43 PM 5.2 The Characteristic Polynomial — Linear Algebra with MATLAB
ans =
2 0 0
2 14 -14
2 12 -12
rref([A-eye(3),zeros(3,1)])
ans =
1 0 0 0
0 1 -1 0
0 0 0 0
x1 = 0
x2 = x3
So v ⃗ is an eigenvector.
0
⎡ ⎤
v⃗ = ⎢ 1 ⎥
⎣ ⎦
1
v = [0 ; 1 ; 1 ];
A*v
ans =
0
1
1
A*V == 1*v
Substituting λ = 3 into A − λI = 0
⃗
A − 3I = 0
A - 3 * eye(3)
ans =
0 0 0
2 12 -14
2 12 -14
Notice the rows of the matrix after the subtraction. This is typical when evaluating A − λI : having a row that is a
scalar multiple of another.
rref([A - 3*eye(3),zeros(3,1)])
https://straightdraw.github.io/Linear/ch5/2.html 3/9
3/4/24, 8:43 PM 5.2 The Characteristic Polynomial — Linear Algebra with MATLAB
ans =
1 6 -7 0
0 0 0 0
0 0 0 0
x1 = −6x2 + 7x3
−6 7
⎡ ⎤ ⎡ ⎤
v⃗ = ⎢ 1 ⎥ x2 + ⎢ 0 ⎥ x3
⎣ ⎦ ⎣ ⎦
0 1
where x2 , x3 are scalars. This means we have two eigenvectors associated with the eigenvalue λ = 3 which
makes sense. The λ = 3 eigenvalue has muliplicity 2. Let’s verify both vectors are eigenvectors. In MATLAB, the |
symbol means AND. The code block below will evaluate as True if and only if both v 1⃗ and v 2⃗ are eigenvectors of A .
A * v1 == 3*v1 | A * v2 == 3*v2
ans =
1
1
1
v1 = [-6 ; 1 ; 0]
A*v1
v1 =
-6
1
0
ans =
-18
3
0
v2 = [7 ; 0 ; 1]
A*v2
v2 =
7
0
1
ans =
21
0
3
Either way, we now know all three unique eigenvectors and the two eigenvalues for A .
https://straightdraw.github.io/Linear/ch5/2.html 4/9
3/4/24, 8:43 PM 5.2 The Characteristic Polynomial — Linear Algebra with MATLAB
−14 −78 26 66
⎡ ⎤
⎢ −2 −12 10 10 ⎥
B = ⎢ ⎥
⎢ 6 27 −4 −24 ⎥
⎣ ⎦
−9 −48 21 41
The charpoly function in MATLAB will produce the coefficients of the characteristic polynomial.
ans =
1 -11 38 -40 0
However, we need to use the syms function from the Symbolic Math Toolbox to have MATLAB do the work for us.
If you downloaded the software, you can repeat the process and select the correct toolbox. The download will be
quick - MATLAB will only download and install the new packages, not the whole program. If you’re working in
MATLAB online, you should not need to do anything different.
syms x
y = charpoly(B,x)
y =
polynomialReduce(y,x)
ans =
If we want to capture the quotient, too, we need to grab both the quotient and remainder of the division as shown.
[r,q] = polynomialReduce(y,x)
r =
q =
We know that any factors that divide q(x) evenly must be of the form:
x ± 1
x ± 2
x ± 4
x ± 5
x ± 8
https://straightdraw.github.io/Linear/ch5/2.html 5/9
3/4/24, 8:43 PM 5.2 The Characteristic Polynomial — Linear Algebra with MATLAB
r =
-630
q2 =
With a remainder of −630, we know that x + 5 is cleary not a factor. Let’s retry it with x − 5 .
r =
q2 =
x^2 - 6*x + 8
r =
q3 =
x - 2
If you were keeping track, you know that we have the following factors:
x − 2
x − 4
x − 5
As with any factoring problem, we can test our factored form by expanding.
z = x*(x-2)*(x-4)*(x-5)
z =
expand(z)
ans =
The expanded form of z matches y , so we have the correct factorization. This means that we now know all our
eigenvalues.
λ = {0, 2, 4, 5}
https://straightdraw.github.io/Linear/ch5/2.html 6/9
3/4/24, 8:43 PM 5.2 The Characteristic Polynomial — Linear Algebra with MATLAB
For λ = 0
rref([B, zeros(4,1)])
ans =
1.0000 0 0 -1.0000 0
0 1.0000 0 -0.6667 0
0 0 1.0000 0 0
0 0 0 0 0
1
⎡ ⎤
⎢ 2/3 ⎥
⃗
v0 = ⎢ ⎥
⎢ 0⎥
⎣ ⎦
1
3
⎡ ⎤
⎢ 2⎥
⃗ = ⎢
v0 ⎥
⎢ 0⎥
⎣ ⎦
3
For λ = 2
ans =
1 0 0 4 0
0 1 0 -2 0
0 0 1 -1 0
0 0 0 0 0
−4
⎡ ⎤
⎢ 2⎥
⃗ = ⎢
v2 ⎥
⎢ 1⎥
⎣ ⎦
1
For λ = 4
ans =
1.0000 0 0 0.6667 0
0 1.0000 0 -1.3333 0
0 0 1.0000 -1.0000 0
0 0 0 0 0
https://straightdraw.github.io/Linear/ch5/2.html 7/9
3/4/24, 8:43 PM 5.2 The Characteristic Polynomial — Linear Algebra with MATLAB
−2/3 −2
⎡ ⎤ ⎡ ⎤
⎢ 4/3 ⎥ ⎢ 4⎥
⃗
v4 = ⎢ ⎥ → ⎢ ⎥
⎢ ⎥
⎢ 1⎥ ⎢ 3⎥
⎣ ⎦ ⎣ ⎦
1 3
For λ = 5
ans =
1 0 0 2 0
0 1 0 -2 0
0 0 1 -2 0
0 0 0 0 0
−2
⎡ ⎤
⎢ 2⎥
⃗ = ⎢
v5 ⎥
⎢ 2⎥
⎣ ⎦
1
B v ⃗ = λv ⃗
v0 = [ 3 ; 2 ; 0 ; 3 ];
v2 = [ -4 ; 2 ; 1 ; 1 ];
v4 = [ -2 ; 4 ; 3 ; 3 ];
B * v0
Print to PDF
ans =
0
0
0
0
B * v2
ans =
-8
4
2
2
B * v4
ans =
-8
16
12
12
https://straightdraw.github.io/Linear/ch5/2.html 8/9
3/4/24, 8:43 PM 5.2 The Characteristic Polynomial — Linear Algebra with MATLAB
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch5/2.html 9/9
3/4/24, 8:44 PM 5.3 Similarity — Linear Algebra with MATLAB
Similar Matrices
Two matrices A and B are similar provided, for some invertible matrix P
−1
A = P BP
The rest of the Margalit section 5.3 is conceptual, not computational, but you should read and understand it.
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch5/3.html 1/1
3/4/24, 8:44 PM 5.4 Diagonalization — Linear Algebra with MATLAB
$$A = PDP^{-1}$$
where D is a diagonal matrix of eigenvalues and P has columns which are the corresponding eigenvectors.
Example
Diagonalize the matrix A .
−3 −7 −2
⎡ ⎤
A = ⎢ 0 −2 0⎥
⎣ ⎦
1 7 0
A = [-3 -7 -2 ; 0 -2 0 ; 1 7 0 ];
syms x
y = charpoly(A,x)
y =
Tip
We can ask the polynomialReduce function to return both quotient and remainder.
[r,q] = polynomialReduce(y,x-1)
r =
18
q =
x^2 + 6*x + 14
[r,q] = polynomialReduce(y,x+1)
https://straightdraw.github.io/Linear/ch5/4.html 1/4
3/4/24, 8:44 PM 5.4 Diagonalization — Linear Algebra with MATLAB
r =
q =
x^2 + 4*x + 4
2
z = (x + 1)(x + 2)
z = (x+1)*(x+2)^2
z =
(x + 1)*(x + 2)^2
expand(z)
ans =
Matrix D
The diagonal matrix we seek must include all the eigenvalues listed as many times as indicated by their
multiplicity.
−1 0 0
⎡ ⎤
D = ⎢ 0 −2 0⎥
⎣ ⎦
0 0 −2
D = [-1 0 0 ; 0 -2 0 ; 0 0 -2 ]
D =
-1 0 0
0 -2 0
0 0 -2
ans =
1 0 1 0
0 1 0 0
0 0 0 0
v1 = [ -1 ; 0 ; 1]
https://straightdraw.github.io/Linear/ch5/4.html 2/4
3/4/24, 8:44 PM 5.4 Diagonalization — Linear Algebra with MATLAB
v1 =
-1
0
1
ans =
1 7 2 0
0 0 0 0
0 0 0 0
v21 = [ -2 ; 0 ; 1];
v22 = [-7 ; 1 ; 0];
A * v1
ans =
1
0
-1
A * v21
ans =
4
0
-2
A * v22
ans =
14
-2
0
This means we have found and confirmed the eigenvectors for A , and we can construct the matrix P . We only
need to ensure that they are in the same order as their associated eigenvalues are in D .
P =
-1 -2 -7
0 0 1
1 1 0
P * D * inv(P)
ans =
-3 -7 -2
0 -2 0
1 7 0
https://straightdraw.github.io/Linear/ch5/4.html 3/4
3/4/24, 8:44 PM 5.4 Diagonalization — Linear Algebra with MATLAB
A =
-3 -7 -2
0 -2 0
1 7 0
A == P * D * inv(P)
ans =
1 1 1
1 1 1
1 1 1
−1 −2 −7
⎡ ⎤
P = ⎢ 0 0 1⎥
⎣ ⎦
1 1 0
−1 0 0
⎡ ⎤
D = ⎢ 0 −2 0⎥
⎣ ⎦
0 0 −2
Exercises
Determine if the following matrices are diagonlizable. If so, determine an invertible matrix C and diagonal matrix
D such that
−1
M = C DC
HW Question 1 HW Question 2
−4 3.5 −3 3 0 4
⎡ ⎤ ⎡ ⎤
A = ⎢ −6 6 −6 ⎥ B = ⎢ 2 −7 20 ⎥
⎣ ⎦ ⎣ ⎦
1 −0.5 0 1 −3 9
Solution Solution
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch5/4.html 4/4
3/4/24, 8:28 PM 1.2 Row Operations — Linear Algebra with MATLAB
We need to learn how to row-reduce matrices. Row-reducing is a skill will use in almost every process and
application problem in the first three-quarters of this course. Let’s begin with the matrix equation: Ax⃗ = v⃗
where:
0 0 −2 −4
⎡ ⎤ ⎡ ⎤
A = ⎢ 2 0 −10 ⎥ and v⃗ = ⎢ 2⎥
⎣ ⎦ ⎣ ⎦
1 1 −3 3
We need to first create MATLAB versions of the example matrix and the vector.
A =
0 0 -2
2 0 -10
1 1 -3
v =
-4
2
3
Matlab treats v ⃗ as a 3 × 1 matrix, and all built-in Matlab matrix operations work for vectors just as they do for
marices.
Augmented Matrices
The solution vector x⃗ can be found by row-reducing the corresponding augmented matrix:
⎡ 0 0 −2 2 ⎤
⃗ = ⎢
[A|v ] 2 0 −10 −4 ⎥
⎢ ⎥
⎣ 1 1 −3 3 ⎦
We create the augmented matrix in Matlab using the code block below. The brackets say “join these two matrices
into one” which MATLAB will do if its possible. Note
B =
0 0 -2 -4
2 0 -10 2
1 1 -3 3
Now the column vector v ⃗ is the fourth column of the matrix. To refer to individual elements of matrix , we can
specify its row and column:
To refer to an entire row (or column), we use a colon which is Matlab’s indexing operator:
B(2,:)
ans =
2 0 -10 2
With the colon is in the column position, all elements in Row 2 are displayed as Matlab indexes through columns 1
through 4. We will use this indexing feature to create row operations.
https://straightdraw.github.io/Linear/ch1/2.html 1/6
3/4/24, 8:28 PM 1.2 Row Operations — Linear Algebra with MATLAB
Row Operations
We can use just the following three elementary row operations to solve any linear system:
B =
2 0 -10 2
0 0 -2 -4
1 1 -3 3
Tip
We would actually prefer the row starting with “1” to be our pivot, and we want the row that starts with zeros at
the bottom. Let’s do all that at once with a multi-row-swap.
B =
1 1 -3 3
2 0 -10 2
0 0 -2 -4
To understand the mapping, remember that the “old” matrix, the one we started with, is on the right side of the
equal sign. The new matrix we are creating is on the left. Row 2 is sent to Row 1, Row 3 to Row 2 and Row 1 to Row
3.
b = B
b =
1 1 -3 3
2 0 -10 2
0 0 -2 -4
Hint
Save your matrix into a new matrix before operating on it. This creates a saved checkpoint of your
matrix. If you mess up later, you can return to this point rather than going all the way back to the
beginning.
As you can in the above example, the lists in the brackets control how the rows will be swapped. Experiment with
different values, and see what happens.
https://straightdraw.github.io/Linear/ch1/2.html 2/6
3/4/24, 8:28 PM 1.2 Row Operations — Linear Algebra with MATLAB
b =
1 1 -3 3
-1 0 5 -1
0 0 -2 -4
Pro Tip
Use lower case letters for matrices while performing row operations. They are a whole lot easier to type.
Now B will be our clean copy of the original augmented matrix, and we can keep working with b .
Let’s do the same with Row 3: multiply through by − 12 . While neither of these row operations are needed, when
working by we often multiply through a row by a non-zero real to make life easier.
b =
1 1 -3 3
-1 0 5 -1
0 0 1 2
Row Operation 3: Replacing a Row with the Sum of that Row and a Scalar
Multiple of Another Row
Pro Tip
so that entry , and thus we will have all zeros below the first pivot:
b(2,:)=b(2,:)+b(1,:)
b =
1 1 -3 3
0 1 2 2
0 0 1 2
REF Completed
If we wish to solve the linear system, often the fastest way is using back substitution, with “back” indicating we
start from the bottom-right and work our way back up to the top-left. Think about the matrix b means in terms of
algebraic equations.
1 1 −3 3
⎡ ⎤
b = ⎢ 0 1 2 2⎥
⎣ ⎦
0 0 1 2
z = 2
https://straightdraw.github.io/Linear/ch1/2.html 3/6
3/4/24, 8:28 PM 1.2 Row Operations — Linear Algebra with MATLAB
y + 2(2) = 2
x + 1(−2) − 3(2) = 3
x − 2 − 6 = 3
x = 11
11
⎡ ⎤
x⃗ = ⎢ −2 ⎥
⎣ ⎦
2
c=b
c =
1 1 -3 3
0 1 2 2
0 0 1 2
To make our way to RREF, we need get zeros above the “1” in the third row.
c(2,:)=c(2,:) - 2 * c(3,:)
c =
1 1 -3 3
0 1 0 -2
0 0 1 2
c =
1 1 0 9
0 1 0 -2
0 0 1 2
c =
1 0 0 11
0 1 0 -2
0 0 1 2
Since the matrix is now in RREF, the solution is just the vector on the right side of the agumentation bar. To check
our solution (beyond comparing it to back-substitution), we need a Matlab version of :
x=c(:,4)
https://straightdraw.github.io/Linear/ch1/2.html 4/6
3/4/24, 8:28 PM 1.2 Row Operations — Linear Algebra with MATLAB
x =
11
-2
2
A*x
v
ans =
-4
2
3
v =
-4
2
3
A*x == v
ans =
1
1
1
If the two expressions were not equal, we would get an array of zero’s instead. We can also check whether our has
produced the correct RREF by the using function RREF.
rref([A,v])
ans =
1 0 0 11
0 1 0 -2
0 0 1 2
Warning
Examples
In the examples below, you can copy the code blocks into MATLAB. When you execute them, all the steps will be
shown down to ref.
By-hand Examples
You should definitely learn to do row-reduction by hand. The first set of examples are great. They either have very
few steps, or very easy calculations in every step, or both.
Example 1
https://straightdraw.github.io/Linear/ch1/2.html 5/6
3/4/24, 8:28 PM 1.2 Row Operations — Linear Algebra with MATLAB
Example 2
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch1/2.html 6/6
3/4/24, 8:30 PM 1.2.1 Lab 1 — Linear Algebra with MATLAB
This lab includes three problems. In each section, you will complete only one of the problems. Read the directions
carefully. You must use MATLAB commands to accomplish the task, and you may not use the rref command
except to check your work. You must show all steps.
When done, export your work as HTML or PDF and upload to the D2L Lab 1 assignment.
Part I: REF
You must row-reduce one of the following matrices to REF.
You may use any variable you like. I had begun to run out, and using the same variable twice causes a good deal of
confusion. If you prefer working with M to the letter I gave you, switch to M .
J = [ 3 2 ;
0 -1 ;
-1 0 ;
0 -1 ;
3 1 ];
M = [ -1 0 ;
0 1 ;
-1 6 ;
1 -6 ;
0 1 ];
S = [ 9 -2 ;
-4 1 ;
1 0 ;
-4 1 ;
0 -1 ];
Part II
You must row-reduce one of the following matrices to REF. Do not go further than REF. You can use text to show
your algebra (back-substitution).
B through G, do B.
H through P, do H.
R through Z, do R.
Pick any of the three.
https://straightdraw.github.io/Linear/ch1/02/1.html 1/3
3/4/24, 8:30 PM 1.2.1 Lab 1 — Linear Algebra with MATLAB
B = [ 0 0 3 -1 -1 ;
1 -2 7 -2 -4 ;
0 0 3 -2 -1 ;
0 5 -1 -1 1 ;
0 0 0 -3 2 ];
H = [ -5 0 5 15 14 ;
0 0 1 3 0 ;
0 5 -1 -2 1 ;
2 0 -2 -5 -5 ;
0 0 2 6 -1 ];
R = [ 0 0 0 -6 -7 ;
-1 0 2 4 19 ;
0 1 0 13 16 ;
0 2 0 5 8 ;
-3 0 7 12 62 ];
Ax ⃗ = v ⃗
A through D, do A.
E through J, do E.
K through Z, do K.
You may use any variable letter you like. I had begun to run out because using the same variable twice in a
dcoument can cause a good deal of confusion.
A = [ -6 2 0 -5 ;
0 0 0 1 ;
-4 1 0 -3 ];
E = [ -4 -10 3 3 ;
0 1 -2 0 ;
5 14 -3 0 ];
K = [ -6 -1 -14 0 ;
2 1 6 0 ;
0 1 0 -1 ];
https://straightdraw.github.io/Linear/ch1/02/1.html 2/3
3/4/24, 8:30 PM 1.2.1 Lab 1 — Linear Algebra with MATLAB
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch1/02/1.html 3/3
3/4/24, 8:31 PM 1.2.2 Homework — Linear Algebra with MATLAB
a(2,:) = 7 * a(2,:)
HW Question 1 HW Question 2
0 0 1 4 8 −11
⎡ ⎤ ⎡ ⎤
⎢ −4 10 13 ⎥ B = ⎢ 2 −1 4 ⎥
A = ⎢ ⎥ ⎣ ⎦
⎢ 0 −1 2⎥ 2 1 0
⎣ ⎦
−2 5 6
Solution
Solution
4 8 −11
⎡ ⎤
19
−4 10 13 ⎢ 0 −5 ⎥
⎡ ⎤ ⎢ ⎥
2
⎢ 0 −1 2⎥ ⎣ 1 ⎦
⎢ ⎥ 0 0 −
2
⎢ 0 0 1⎥
⎣ ⎦
0 0 0
HW Question 3 HW Question 4
https://straightdraw.github.io/Linear/ch1/02/2.html 1/2
3/4/24, 8:31 PM 1.2.2 Homework — Linear Algebra with MATLAB
8 0 −9 4 3 −28 −25
⎡ ⎤
D = [ ]
C = ⎢ 0 2 1 ⎥ −4 0 23 20
⎣ ⎦
2 −1 −4
Solution
Solution
4 3 −28 −25
[ ]
8 0 −9 0 3 −5 −5
⎡ ⎤
⎢ 0 2 1⎥
5
⎣ 0 0 − ⎦
4
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch1/02/2.html 2/2
3/4/24, 8:32 PM 1.3 Parameterized Solutions — Linear Algebra with MATLAB
Example 1
−2 2 0 6
A = [ ]
0 0 −1 2
We have two pivots, b 11 = −2 and b 23 = −1 . The pivot columns correspond to basic variables while the other
columns correspond to free variables. Let’s solve as far we as we can.
Tip
Usually, we back-substitute, starting from bottom-right and working our way back up toward top-left.
Cleary,
x3 = −2
−2x1 + 2x2 = 6
x1 = −3 + x2
Parameterized Solutions
Now we know the solutions have a very specific form. The Margalit and Robanoff textbook uses the following
notation to express it:
−3 + x2
⎡ ⎤
x⃗ = ⎢ x2 ⎥
⎣ ⎦
−2
or
−3 x2
⎡ ⎤ ⎡ ⎤
x⃗ = ⎢ 0 ⎥ + ⎢ x2 ⎥
⎣ ⎦ ⎣ ⎦
−2 0
−3 1
⎡ ⎤ ⎡ ⎤
x⃗ = ⎢ 0 ⎥ + ⎢ 1 ⎥ x2
⎣ ⎦ ⎣ ⎦
−2 0
https://straightdraw.github.io/Linear/ch1/3.html 1/3
3/4/24, 8:32 PM 1.3 Parameterized Solutions — Linear Algebra with MATLAB
where the x2 can be any real number. Since x2 is a free variable, then we can plug any value for it that we like, and
the result will still be a solution to our linear system.
Example 2
⎡ 15 9 −4 −17 ⎤
B = ⎢
⎢ −5 −3 4 11 ⎥
⎥
⎣ 0 0 0 1 ⎦
The steps in the code block will row-reduce the augmented matrix. Only the result is shown below.
Tip
Placing a semicolon at the end of a line tells MATLAB to execute that line but suppress the result.
B= [ 15 9 -4 -17 ; -5 -3 4 11 ; 0 0 0 1
];
B([1 2],:) = B([2 1],:);
B(2,:) = B(2,:) + 3 * B(1,:)
B =
-5 -3 4 11
0 0 8 16
0 0 0 1
−5 −3 4 11
⎡ ⎤
A = ⎢ 0 0 8 16 ⎥
⎣ ⎦
0 0 0 1
claims that 0 = 1 which is not possible, which means there are no solutions to this linear system.
Example 3
Suppose we have the following REF of the augmented matrix
⎡ 3 −3 0 9 0 6 ⎤
C = ⎢
⎢ 0 0 1 5 0 1
⎥
⎥
⎣ ⎦
0 0 0 0 5 5
x3 = 1 − 5x4
and
which simplifies to
x1 = 2 + x2 − 3x4
Using the Margilit and Robanoff notation: (x1 , x2 , x3 , x4 , x5 ) = (2 + x2 − 3x4 , x2 , 1 − 5x4 , x4 , 5) , but we
will use the expanded form shown below in this supplement.
https://straightdraw.github.io/Linear/ch1/3.html 2/3
3/4/24, 8:32 PM 1.3 Parameterized Solutions — Linear Algebra with MATLAB
⎡
2 +x2 −3x4
⎤ ⎡
2
⎤ ⎡
x2
⎤ ⎡
−3x4
⎤ Warning
⎢ x2 ⎥ ⎢ 0 ⎥ ⎢ x2 ⎥ ⎢ 0 ⎥
⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ We have not learned about vectors a
x⃗ = ⎢ 1
⎢ −5x4
⎥ = ⎢
⎥ ⎢ 1
⎥ + ⎢
⎥ ⎢ 0
⎥ + ⎢
⎥ ⎢ −5x4
⎥
⎥ operations. That’s in chapter 2, but th
⎢
⎢ x4
⎥
⎥
⎢
⎢ 0
⎥
⎥
⎢
⎢ 0
⎥
⎥
⎢
⎢ x4
⎥
⎥ arithmetic I’m using is not difficult.
⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦
5 5 0 0
2 1 −3
⎡ ⎤ ⎡ ⎤ ⎡ ⎤
⎢ 0⎥ ⎢ 1 ⎥ ⎢ 0⎥
⎢ ⎥ ⎢ ⎥ ⎢ ⎥
x⃗ = ⎢ ⎥ + ⎢ 0 ⎥x + ⎢ ⎥x
⎢ 1⎥ ⎢ ⎥ 2 ⎢ −5 ⎥ 4
⎢ ⎥ ⎢ ⎥ ⎢ ⎥
⎢ 0⎥ ⎢ 0 ⎥ ⎢ 1 ⎥
⎣ ⎦ ⎣ ⎦ ⎣ ⎦
5 0 0
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch1/3.html 3/3
3/4/24, 8:32 PM 1.3.1 Lab 2 — Linear Algebra with MATLAB
Your assignment is to solve three linear systems, and write the solutions in parametric form (vector form). To help
entering vectors in Dollar Sign Math (LaTeX), be sure to download and use the dsm script included in the Lab
Assignment. You can also access the code for the script here.
Note
Each matrix below is an augmented matrix that represents a linear system that can be solved.
J = [5 -1 -2 5 4 ;
0 -1 5 5 1 ;
0 0 0 5 -1 ] ;
M = [-2 -1 1 3 -2 ;
0 0 -2 -1 4 ;
0 0 0 -1 1 ] ;
S = [3 -1 3 -1 5 ;
0 3 0 2 4 ;
0 0 0 2 1 ] ;
A through D, do A.
D through J, do D.
J through Z, do J.
A = [1 2 2 0 ;
3 6 10 -2 ] ;
https://straightdraw.github.io/Linear/ch1/03/1.html 1/2
3/4/24, 8:32 PM 1.3.1 Lab 2 — Linear Algebra with MATLAB
D = [4 -1 -2 -9 ;
8 -2 -3 -7 ] ;
J = [-2 1 -1 0 ;
2 -1 1 0 ] ;
B through G, do B.
H through Q, do H.
R through Z, do R.
A pick any of the three.
B = [ 0 0 3 -1 3 4 ;
1 1 0 2 1 0 ;
-1 -1 0 -2 4 5 ;
-1 -1 0 -2 4 5 ] ;
H = [ 3 -2 2 -2 5 1 ;
0 0 0 0 -1 0 ;
9 -6 6 -6 11 3 ;
12 -5 10 -3 24 7 ] ;
R = [ 1 1 2 5 -1 4 ;
5 5 10 30 -5 19 ;
14 14 28 85 -14 53 ;
0 0 1 -2 2 5 ] ;
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch1/03/1.html 2/2
3/4/24, 8:33 PM 2.1 Vectors — Linear Algebra with MATLAB
2.1 Vectors
Print to PDF
Operations
Vector Addition
The addition of vectors occurs component-wise. For two vectors in R4 :
3 4 7
⎡ ⎤ ⎡ ⎤ ⎡ ⎤
⎢ −1 ⎥ ⎢ 5⎥ ⎢ 4⎥
v⃗ = ⎢ ⎥ , u⃗ = ⎢ ⎥, v ⃗ + u⃗ = ⎢ ⎥
⎢ 2⎥ ⎢ −2 ⎥ ⎢ 0⎥
⎣ ⎦ ⎣ ⎦ ⎣ ⎦
9 −5 4
If two vectors have a different number of components, they cannot be added or subtracted.
Scalar Multiplication
Suppose we take a real number r . We can multiply a vector by this scalar by multiplying each component of the
vector by r . For example, if r = 3 , then:
3 9
⎡ ⎤ ⎡ ⎤
⎢ −1 ⎥ ⎢ −3 ⎥
rv ⃗ = 3 ⎢ ⎥ = ⎢ ⎥
⎢ 2⎥ ⎢ 6⎥
⎣ ⎦ ⎣ ⎦
9 27
Vector Subtraction
To substract v ⃗ − u⃗ we add v ⃗ to (−1)u⃗.
3 −4 −1
⎡ ⎤ ⎡ ⎤ ⎡ ⎤
⎢ −1 ⎥ ⎢ −5 ⎥ ⎢ −6 ⎥
v ⃗ − u⃗ = ⎢ ⎥ + ⎢ ⎥ = ⎢ ⎥
⎢ 2⎥ ⎢ 2⎥ ⎢ 4⎥
⎣ ⎦ ⎣ ⎦ ⎣ ⎦
9 5 14
v = [3 ; -1 ; 2 ; 9]
u = [4 ; 5 ; -2 ; -5]
v =
3
-1
2
9
u =
4
5
-2
-5
https://straightdraw.github.io/Linear/ch2/1.html 1/3
3/4/24, 8:33 PM 2.1 Vectors — Linear Algebra with MATLAB
v + u
ans =
7
4
0
4
v - u
ans =
-1
-6
4
14
3 * v
ans =
9
-3
6
27
Be sure to spend time reading and interacting Margalit and Robanoff textbook to visualize what it means to add,
subtract vectors and to take the scalar multiple of a vector.
Note
In this course, the word scalar amost always means real number. However, we can have complex-valued
matrices and vectors. In those cases, a scalar would be a complex number.
5 0 3
⎡ ⎤ ⎡ ⎤ ⎡ ⎤
5 0 3 26
⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤
⃗ + c2 v2
c1 v1 ⃗ + c3 v3
⃗ = 4⎢ 3 ⎥ − ⎢ 2 ⎥ + 2 ⎢ 4 ⎥ = ⎢ 18 ⎥
⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦
−2 5 3 −7
v1 = [5 ; 3 ; -2]
v2 = [ 0; 2 ; 5 ]
v3 = [3 ; 4 ; 3]
https://straightdraw.github.io/Linear/ch2/1.html 2/3
3/4/24, 8:33 PM 2.1 Vectors — Linear Algebra with MATLAB
v1 =
5
3
-2
v2 =
0
2
5
v3 =
3
4
3
4 * v1 - v2 + 2 * v3
ans =
26
18
-7
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch2/1.html 3/3
3/4/24, 8:34 PM 2.2 Vector Equations and Spans — Linear Algebra with MATLAB
⃗
⃗ + c2 v2
c1 v1 ⃗ + ⋯ + cnvn
⃗ = b
As shown in Margalit and Robanoff, we can find the weights c 1 , c 2 , … , c n by row-reducing an augmented matrix.
Let’s rewrite the equation above slightly by calling the weights x1 , x2 , … , xn .
⃗
x1 v⃗1 + x2 v⃗2 + ⋯ + xn v⃗n = b
If the columns of the matrix A are comprised of the vectors v 1⃗ , v 2⃗ , … , v n⃗ , we would write
⃗ , v2
A = [v 1 ⃗ , … , v3
⃗ ]
and then the above vector equations are equivalent to the matrix equations
⃗
Ax ⃗ = b
We already know from Chapter 1 that the solution vector x⃗ can be found by row-reducing the augmented matrix
⃗
[A|b ] .
Example 1
Determine if the vector b ⃗ in the span of the vectors
5 0 3
⎡ ⎤ ⎡ ⎤ ⎡ ⎤
⃗ = ⎢
v1 ⃗ = ⎢ 2 ⎥ , v3
3 ⎥ , v2 ⃗ = ⎢ 4⎥
⎣ ⎦ ⎣ ⎦ ⎣ ⎦
−2 5 3
where
4
⎡ ⎤
⃗
b = ⎢ 0⎥
⎣ ⎦
2
v1 = [5 ; 3 ; -2]
v2 = [ 0; 2 ; 5 ]
v3 = [3 ; 4 ; 3]
b = [ 4 ; 0 ; 2]
https://straightdraw.github.io/Linear/ch2/2.html 1/3
3/4/24, 8:34 PM 2.2 Vector Equations and Spans — Linear Algebra with MATLAB
v1 =
5
3
-2
v2 =
0
2
5
v3 =
3
4
3
b =
4
0
2
A =
5 0 3
3 2 4
-2 5 3
[A,b]
ans =
5 0 3 4
3 2 4 0
-2 5 3 2
rref([A,b])
ans =
1.0000 0 0 5.2308
0 1.0000 0 6.9231
0 0 1.0000 -7.3846
The components of the vector x⃗ are the weights of the linear combination. Let’s use the rats function to better
understand what rational numbers we’re talking about.
rats(rref([A,b]))
ans =
Mathematicians often write vectors like this as scalar multiples because they look much better.
68
68 ⎡ 13
⎤
⎡ ⎤
1
⎢ 90 ⎥
x⃗ = ⎢ 90 ⎥ instead of x⃗ = ⎢ ⎥
13 ⎢ 13 ⎥
⎣ ⎦
−96 ⎣ −96 ⎦
13
https://straightdraw.github.io/Linear/ch2/2.html 2/3
3/4/24, 8:34 PM 2.2 Vector Equations and Spans — Linear Algebra with MATLAB
Example 2
Determine if the vector b ⃗ in the span of the vectors v 1⃗ , v 2⃗ where
0 −1 5
⎡ ⎤ ⎡ ⎤ ⎡ ⎤
⎢ 4⎥ ⎢ 5⎥ ⃗ ⎢ −17 ⎥
⃗
v1 = ⎢ ⃗ = ⎢
⎥ , v2 ⎥ and b = ⎢ ⎥
⎢ 0⎥ ⎢ 0⎥ ⎢ 0⎥
⎣ ⎦ ⎣ ⎦ ⎣ ⎦
4 −1 3
v1 = [0;4;0;4]
v2 = [-1;5;0;-1]
b = [5 ; -17 ; 0 ; 3]
v1 =
0
4
0
4
v2 =
-1
5
0 Print to PDF
-1
b =
5
-17
0
3
M = [v1,v2]
M =
0 -1
4 5
0 0
4 -1
rref([M, b])
ans =
1 0 0
0 1 0
0 0 1
0 0 0
We see the third row is impossible since (0)x1 + (0)x2 ≠ 1 . Since the matrix equations are inconsistent, there is
no linear cobination of the vectors v 1⃗ , v 2⃗ that is equal to b ⃗ and, thus,
⃗
⃗ , v2
b ∉ Span{v 1 ⃗ }
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch2/2.html 3/3
3/4/24, 8:35 PM 2.3 Matrix Equations — Linear Algebra with MATLAB
The key to understanding matrix multiplication is the dot product of two vectors. The book calls this the row-
column recipe for matrix-vector multiplication.
−1 1
⎡ ⎤ ⎡ ⎤
x⃗ = ⎢ 1 ⎥ , y⃗ = ⎢ 3⎥
⎣ ⎦ ⎣ ⎦
5 −1
MATLAB has a dot product function called, not too surprisingly, dot.
x = [-1 ; 1 ; 5]
y = [ 1 ; 3 ; -1]
dot(x,y)
x =
-1
1
5
y =
1
3
-1
ans =
-3
When multiplying a matrix by a vector, as in Ax,⃗ we take the dot product of each row with the vector.
−2
⎡ ⎤
3 −2 3 −2
⎡ ⎤
⎢ 1⎥
A = ⎢ −2 −2 0 1 ⎥, x⃗ = ⎢ ⎥
⎢ 5⎥
⎣ ⎦
0 4 5 1
⎣ ⎦
0
This means that the matrix must have the same number of columns as there are components (rows) of x⃗. If
Ax ⃗ = b
⃗
, then the first component of b ⃗ is the dot product of the first row of A with x⃗.
3 −2
⎡ ⎤ ⎡ ⎤
⎢ −2 ⎥ ⎢ 1⎥
⎢ ⎥ ⋅ ⎢ ⎥ = −6 − 2 + 15 + 0 = 7
⎢ 3⎥ ⎢ 5⎥
⎣ ⎦ ⎣ ⎦
−2 0
The second component is the product of the second row and x⃗, and so on.
−2 −2
⎡ ⎤ ⎡ ⎤
⎢ −2 ⎥ ⎢ 1⎥
⎢ ⎥ ⋅ ⎢ ⎥ = −4 − 2 + 0 + 0 = −6
⎢ 0⎥ ⎢ 5⎥
⎣ ⎦ ⎣ ⎦
1 0
0 −2
⎡ ⎤ ⎡ ⎤
⎢ 4⎥ ⎢ 1⎥
⎢ ⎥ ⋅ ⎢ ⎥ = 0 + 4 + 25 + 0 = 29
⎢ 5⎥ ⎢ 5⎥
⎣ ⎦ ⎣ ⎦
1 0
We can have MATLAB do the multiplication to verify our work that shows
https://straightdraw.github.io/Linear/ch2/3.html 1/2
3/4/24, 8:35 PM 2.3 Matrix Equations — Linear Algebra with MATLAB
7
⎡ ⎤
Ax ⃗ = ⎢ 2⎥
⎣ ⎦
29
If we create vectors r 1⃗ , r 2⃗ , r 3⃗ from the rows of A , we can use the dot product function to check.
A = [3 -2 3 -2 ; -2 -2 0 1 ; 0 4 5 1 ];
r1 = A(1,:) Note
r2 = A(2,:)
r3 = A(3,:) The v⃗ is the same vector whether it is
x = [-2 ; 1 ; 5 ; 0] as a column vector
1
⎡ ⎤
r1 = v⃗ = ⎢ 2 ⎥
⎣ ⎦
3
3 -2 3 -2
or as a row vector
v⃗ = [ 1 2 3 ].
r2 =
-2 -2 0 1
r3 =
0 4 5 1
x =
-2
1
5
0
b =
7
2
29
b = A * x
b =
7
2
29
This explains why, when we row reduce the augmented matrix [A|b ]⃗ , we find the vector x⃗.
rref([A,b])
ans =
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch2/3.html 2/2
3/4/24, 8:35 PM 2.4 Solution Sets — Linear Algebra with MATLAB
⃗
Ax ⃗ = 0
it is called an homogeneous system. We solve the honogeneous system in excatly the same way as before, by row
reducing the augmented matrix [A, 0]⃗ . For example, if
5 2 −1 4
A = [ ]
5 −2 0 −2
then
5 2 −1 4 0
⃗
[A, 0 ] = [ ]
5 −2 0 −2 0
A=[ 5 2 -1 4 ;
5 -2 0 -2 ]
A =
5 2 -1 4
5 -2 0 -2
Tip
Use a lower case variable name for a matrix if you are row reducing it as a lowercase letter is much
easier to type.
a = zeros(3,2)
5 2 -1 4 0
5 -2 0 -2 0
0 0
⎡ ⎤
⎢ 0 0⎥
⎣ ⎦
0 0
R2 = R2 − R1
b = a;
b(2,:) = b(2,:) - (b(1,:))
b =
5 2 -1 4 0
0 -4 1 -6 0
We can solve for the basic variables x1 , x2 in terms of the free variables x3 , x4 .
1 3 ⟹
x2 = x3 − x4
4 2
https://straightdraw.github.io/Linear/ch2/4.html 1/3
3/4/24, 8:35 PM 2.4 Solution Sets — Linear Algebra with MATLAB
1 3
5x1 + 2 ( x3 − x4 ) = x3 − 4x4
4 2
⟹
1 3
x2 = x3 − x4
4 2
1
5x1 + x3 − 3x4 = x3 − 4x4
2
⟹
1 3
x2 = x3 − x4
4 2
1
5x1 = x3 − x4
2
⟹
1 3
x2 = x3 − x4
4 2
1 1
x1 = x3 − x4
10 5
1 3
x2 = x3 − x4
4 2
x1
⎡ ⎤
⎢ x2 ⎥
Our solution vector is of the form x⃗ = ⎢ ⎥ where
⎢x ⎥
3
⎣ ⎦
x4
1 1 1 1
x1 x3 − x4 −
⎡ 10 5 ⎤ ⎡ ⎤ ⎡ 5 ⎤
⎡ ⎤ 10
1 3 1 3
⎢ x4 ⎥ ⎢ ⎥ ⎢ − ⎥
⎢ x2 ⎥ x3 −
⎢ 4 2 ⎥ = ⎢ 4 ⎥x + ⎢ 2 ⎥x
⎢ ⎥ = 3 4
⎢ ⎥ ⎢ ⎥ ⎢ ⎥
⎢x ⎥
3 ⎢ x3 ⎥ ⎢ 1 ⎥ ⎢ 0 ⎥
⎣ ⎦
x4 ⎣ ⎦ ⎣ ⎦ ⎣ ⎦
x4 0 1
1 1
−
⎡ 10 ⎤ ⎡ 5 ⎤
⎢ 1 ⎥ ⎢ −3 ⎥
⎢ 4 ⎥ and ⎢ 2 ⎥
⎢ ⎥ ⎢ ⎥
⎢ 1⎥ ⎢ 0 ⎥
⎣ ⎦ ⎣ ⎦
0 1
is a solution to the homogeneous system of equations, which we can check using MATLAB
u = [.1 ; .25 ; 1 ; 0]
v = [-.2 ; -1.5 ; 0 ; 1]
u =
0.1000
0.2500
1.0000
0
v =
-0.2000
-1.5000
0
1.0000
Let’s set the vector x⃗ equal to some linear combination of v ⃗ and u⃗ and multiply the result by the matrix A .
x = 2 * u + 4 * v;
A * x
ans =
0
0
https://straightdraw.github.io/Linear/ch2/4.html 2/3
3/4/24, 8:35 PM 2.4 Solution Sets — Linear Algebra with MATLAB
Because Ax⃗ = 0
⃗
for all linear combinations of v ,⃗ u⃗ (and you should try several), we know that the solution set of
these homogeneous equations is the
⃗ v}
Span{u, ⃗
and has two dimensions. As the textbooks remarks, the dimension of the subspace containing the solution set has
dimension equal to the number of free variables in the system. For example, consider the linear system
represented by the following 3 × 6 coefficent matrix.
−4 6 3 −2 1 −3
⎡ ⎤
⎢ −2 5 0 5 4 9⎥
⎣ ⎦
5 2 6 −2 6 6
We know that this matrix will have either 1, 2 or 3 pivots and therefore 3, 4 or 5 free variables. We can row-reduce
to verify which situation we have.
A = [ -4 6 3 -2 1 -3 ;
-2 5 0 5 4 9 ; See also
5 2 6 -2 6 6 ] ;
If you are having trouble understandi
rref(A) why we know we must have 3, 4 or 5
variables, please review section 2.4 o
textbook.
ans =
Since we have three pivots and, more to the point, three free variables, the solution set of the homogeneous
system [A|0]⃗ will have dimension three.
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch2/4.html 3/3
3/4/24, 8:35 PM 2.4.1 Lab 3 — Linear Algebra with MATLAB
2.4.1 Lab 3
⎣ ⎦
7
0 3 1
⎡ ⎤ ⎡ ⎤ ⎡ ⎤
⎢ 0⎥ ⎢ 6⎥ ⎢ 1⎥
A = [a1, a2, a3]
⃗
v1 = ⎢ ⃗ = ⎢
⎥ , v2 ⃗ = ⎢
⎥ , v3 ⎥
⎢ −1 ⎥ ⎢ 0⎥ ⎢ 1⎥
⎣ ⎦ ⎣ ⎦ ⎣ ⎦
0 12 2
−1
⎡ ⎤
⎢ 0⎥
x⃗ = ⎢ ⎥
⎢ −1 ⎥
⎣ ⎦
−1
is in the Span ⃗ , x2
= {x1 ⃗ , x3
⃗ } where
−2 14 −1
⎡ ⎤ ⎡ ⎤ ⎡ ⎤
⎢ 0⎥ ⎢ 5⎥ ⎢ −1 ⎥
⃗
x1 = ⎢ ⃗ = ⎢
⎥ , x2 ⃗ = ⎢
⎥ , x3 ⎥
⎢ 0⎥ ⎢ 0⎥ ⎢ 1⎥
⎣ ⎦ ⎣ ⎦ ⎣ ⎦
0 0 1
x1 = [-2 ; 0 ; 0 ; 0 ] ;
x2 = [14 ; 5 ; 0 ; 0 ] ;
x3 = [-1 ; -1 ; 1 ; 1 ] ;
x = [-1 ; 0 ; -1 ; -1 ] ;
2
⎡ ⎤
⎢ −3 ⎥
y⃗ = ⎢ ⎥
⎢ −1 ⎥
⎣ ⎦
−1
3 3 5
⎡ ⎤ ⎡ ⎤ ⎡ ⎤
⎢ −3 ⎥ ⎢ 2⎥ ⎢ 3⎥
⃗
y1 = ⎢ ⃗ = ⎢
⎥ , y2 ⃗ = ⎢
⎥ , y3 ⎥
⎢ 0⎥ ⎢ 0⎥ ⎢ 1⎥
⎣ ⎦ ⎣ ⎦ ⎣ ⎦
0 0 0
https://straightdraw.github.io/Linear/ch2/04/1.html 1/3
3/4/24, 8:35 PM 2.4.1 Lab 3 — Linear Algebra with MATLAB
y1 = [3 ; -3 ; 0 ; 0 ] ;
y2 = [3 ; 2 ; 0 ; 0 ] ;
y3 = [5 ; 3 ; 1 ; 0 ] ;
y = [2 ; -3 ; -1 ; -1 ] ;
Hint
You can create a row vector from the row of a matrix, for example, the second row as shown below.
A = randi(5,5,4)
r2 = A(2,:)
Multiply Av ⃗ where
7
⎡ ⎤
7 −3 6 5 9
⎡ ⎤
⎢ −1 ⎥
⎢ 7 2 5 −3 −4 ⎥ ⎢ ⎥
A = ⎢ ⎥ , v⃗ = ⎢ 1⎥
⎢ ⎥
⎢ −3 7 6 4 0 ⎥ ⎢ ⎥
⎢ −2 ⎥
⎣ ⎦
0 5 8 −3 4
⎣ ⎦
8
A = [7 -3 6 5 9 ;7 2 5 -3 -4 ;-3 7 6 4 0 ;0 5 8 -3 4 ] ;
v = [ 7 ; -1 ; 1 ; -2 ; 8 ] ;
6
⎡ ⎤
2 6 −2 −2 −5
⎡ ⎤
⎢ −1 ⎥
⎢ 7 −3 −3 10 10 ⎥ ⎢ ⎥
D = ⎢ ⎥ , x⃗ = ⎢ 3⎥
⎢ ⎥
⎢ 3 5 −3 −5 −1 ⎥ ⎢ ⎥
⎢ −1 ⎥
⎣ ⎦
−2 5 −3 10 3
⎣ ⎦
7
D = [2 6 -2 -2 -5 ;7 -3 -3 10 10 ;3 5 -3 -5 -1 ;-2 5 -3 10 3 ] ;
x = [6 ;-1 ;3 ;-1 ;7 ] ;
Multiply J y ⃗ where
7
⎡ ⎤
7 −3 −1 2 2
⎡ ⎤
⎢ 0⎥
⎢ 9 7 −2 10 2⎥ ⎢ ⎥
J = ⎢ ⎥ , y⃗ = ⎢ 6⎥
⎢ ⎥
⎢ 2 9 3 4 7⎥ ⎢ ⎥
⎢ 5⎥
⎣ ⎦
8 8 1 10 6
⎣ ⎦
−2
J = [7 -3 -1 2 2 ;9 7 -2 10 2 ;2 9 3 4 7 ;8 8 1 10 6 ] ;
y = [7 ;0 ;6 ;5 ;-2 ] ;
https://straightdraw.github.io/Linear/ch2/04/1.html 2/3
3/4/24, 8:35 PM 2.4.1 Lab 3 — Linear Algebra with MATLAB
B through G, do B.
H through Q, do H.
R through Z, do R.
A pick any of the three.
⎡ 7 18 39 −16 −1 0 ⎤
B = ⎢
⎢ 0 −1 −1 2 0 0
⎥
⎥
⎣ ⎦
−9 −22 −49 18 1 0
ans =
7 18 39 -16 -1 0
0 -1 -1 2 0 0
-9 -22 -49 18 1 0
⎡ 1 −5 −2 −1 −4 0 ⎤
H = ⎢
⎢ −5 25 7 8 20 0
⎥
⎥
⎣ ⎦
−2 10 −2 11 11 0
H = [1 -5 -2 -1 -4 ;-5 25 7 8 20 ;-2 10 -2 11 11 ] ;
z = zeros(3,1) ;
[H,z]
1 -5 -2 -1 -4 0
-5 25 7 8 20 0
-2 10 -2 11 11 0
6 6 −12 37 −8
⎡ ⎤
R = ⎢ −4 6 −2 −7 3⎥
⎣ ⎦
2 −2 0 5 −2
R = [6 6 -12 37 -8 ;-4 6 -2 -7 3 ;2 -2 0 5 -2 ] ;
z = zeros(3,1) ;
[R,z]
ans =
6 6 -12 37 -8 0
-4 6 -2 -7 3 0
2 -2 0 5 -2 0
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch2/04/1.html 3/3
3/4/24, 8:13 PM 2.5 Linear Independence — Linear Algebra with MATLAB
Linearly Independent
A set of vectors {v 1 , v 2 , . . . , v k } is linearly independent if the vector equation
⃗ + x2 v 2
x1 v 1 ⃗ + ⋯ + xk v k
⃗ = 0
⃗
has only the trivial solution.
Note
The matrix equations Ax⃗ = 0⃗ always has the trivial solution x⃗ = 0⃗ . Whenever the zero vector is a
solution, we refer to it as the trivial solution of the system.
Linearly Dependent
A set of vectors that is not linearly indepedent.
If the set of vectors {v 1 , v 2 , . . . , v k } is linearly dependent, then there exists a linear combination of the those
vectors equal to the zero vector. This means there is a solution
x1
⎡ ⎤
⎢ x2 ⎥
x⃗ = ⎢ ⎥
⎢ ⎥
⎢ ⋮⎥
⎣ ⎦
xk
with at least one component not equal to zero such that to dot product equals zero:
⃗ + x2 v 2
⃗ + ⋯ + xk v k
⃗ = 0 ⃗
x1 v 1
−1 −2 0 1 4 1
⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤
x1 = ⎢ −2 ⎥ , x2 = ⎢ 1 ⎥ , x3 = ⎢ 4 ⎥ y 1 = ⎢ 5 ⎥ , y 2 = ⎢ 2 ⎥ , y 3 = ⎢ −1 ⎥
⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦
−2 1 3 5 5 0
Let’s first create a matrix X the columns of which are the vectors {x1 , x2 , … , x3 } .
−1 −2 0
⎡ ⎤
X = ⎢ −2 1 4⎥
⎣ ⎦
−2 1 3
We need to know how many pivots there are because pivots correspond to the linearly independent vectors.
X = [ -1 -2 0 ;
-2 1 4 ;
-2 1 3 ] ;
rref(X)
ans =
1 0 0
0 1 0
0 0 1
Because all three columns are pivot columns, the vectors are linearly indpendent.
1 4 1
⎡ ⎤
Y = ⎢ 5 2 −1 ⎥
⎣ ⎦
5 5 0
https://straightdraw.github.io/Linear/ch2/5.html 1/3
3/4/24, 8:13 PM 2.5 Linear Independence — Linear Algebra with MATLAB
Y = [ 1 4 1 ;
5 2 -1 ;
5 5 0 ] ;
rref(Y)
ans =
1.0000 0 -0.3333
0 1.0000 0.3333
0 0 0
This set of vectors is linearly dependent because there are only two pivots, not three. Therefore, there must be a
non-trivial solution to the homogeneous system of equations.
⎡ 1 4 1 ⎤ ⎡ 1 0 −0.33333 ⎤
⎢ ⎥ → ⎢ ⎥
⎢ 5 2 −1 ⎥ ⎢ 0 1 0.33333 ⎥
⎣ ⎦ ⎣ ⎦
5 5 0 0 0 0
1
−
We have a found a solution vector v ⃗ which indicates that a linear combination of the first two vectors
3
= [ ]
1
3
will result in the third vector.
y1 = Y(:,1)
y2 = Y(:,2)
y3 = Y(:,3)
y1 =
1
5
5
y2 =
4
2
5
y3 =
1
-1
0
- y1/3 + y2/3
ans =
1
-1
0
We can can check using a the logical operator for “equal to”:
- y1/3 + y2/3 == y3
https://straightdraw.github.io/Linear/ch2/5.html 2/3
3/4/24, 8:13 PM 2.5 Linear Independence — Linear Algebra with MATLAB
ans =
1
1
1
1 4 1
⎡ ⎤ ⎡ ⎤ ⎡ ⎤
1 1
−( )⎢ 5⎥ + ( ) ⎢ 2 ⎥ = ⎢ −1 ⎥
3 3
⎣ ⎦ ⎣ ⎦ ⎣ ⎦
5 5 0
⃗
⃗ , v2
{v 1 ⃗ , ⋯ , vk
⃗ , b}
is linearly dependent. The linear dependence relation for b ⃗ is the linear combination of the vectors {v 1⃗ , v 2⃗ , … , v k⃗ }
such that
⃗
⃗ + c2 v2
b = c1 v1 ⃗ + ⋯ + ckvk
⃗
which is precisely what it means for a vector to be in the span of a set of vectors.
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch2/5.html 3/3
3/4/24, 8:36 PM 2.6 Subspaces — Linear Algebra with MATLAB
2.6 Subspaces
The visualizations in the textbook’s Section 2.6 are very valuable. You should spend time with all of the interactive
modules and take time with the definitions and theorems.
The key task in the section is finding the solution set of the null space.
Null Space
The set of all solution vectors to the homogenenous equations.
4 −18 −21
⎡ ⎤
A = ⎢ −4 30 33 ⎥
⎣ ⎦
0 1 1
A = [ 4 -18 -21 ;
-4 30 33 ;
0 1 1 ]
A =
4 -18 -21
-4 30 33
0 1 1
To dtermine the null space, we need to augment the matrix A with the zero vector.
[A,zeros(3,1)]
ans =
4 -18 -21 0
-4 30 33 0
0 1 1 0
rref([A,zeros(3,1)])
ans =
1.0000 0 -0.7500 0
0 1.0000 1.0000 0
0 0 0 0
Now we write the solution set in vector form. The first step is to write all basic variables in terms of the free
variables.
3
x1 = x3
4
x2 = −x3
⎡ 4 ⎤
x⃗ = ⎢ −1 ⎥
⎣ ⎦
1
To verify the solution is correct, we can create the vector x⃗ and evaluate what happens when we take scalar
multiples of it and multiply by B.
https://straightdraw.github.io/Linear/ch2/6.html 1/4
3/4/24, 8:36 PM 2.6 Subspaces — Linear Algebra with MATLAB
x = [ 3/4 ; -1 ; 1]
x =
0.7500
-1.0000
1.0000
A * (5 * x)
ans =
0
0
0
This isn’t proof that any scalar multiple of x⃗ is a solution, but we can check several randomly chosen scalar
multiples.
−1 4 1
⎡ ⎤
B = ⎢ −3 12 7 ⎥
⎣ ⎦
0 1 −2
B = [ -1 4 1 ; -3 12 7 ; 0 1 -2 ]
rref([B, zeros(3,1)])
B =
-1 4 1
-3 12 7
0 1 -2
ans =
1 0 0 0
0 1 0 0
0 0 1 0
Clearly, the only solution to the homogeneous equations is the zero vector which makes sense. Because there are
three pivots, there are no free variables. We use the notation below for the null space of a matrix.
Null(B) = 0 ⃗
Example 3
Find the null space for matrix C .
0 0 1 −2
⎡ ⎤
C = ⎢ −12 43 27 9⎥
⎣ ⎦
−2 7 4 1
C = [ 0 0 1 -2 ;
-12 43 27 9 ;
-2 7 4 1 ]
[C , zeros(3,1)]
c = rref([C , zeros(3,1)])
https://straightdraw.github.io/Linear/ch2/6.html 2/4
3/4/24, 8:36 PM 2.6 Subspaces — Linear Algebra with MATLAB
C =
0 0 1 -2
-12 43 27 9
-2 7 4 1
ans =
0 0 1 -2 0
-12 43 27 9 0
-2 7 4 1 0
c =
1 0 0 27 0
0 1 0 9 0
0 0 1 -2 0
Clearly, x1 ,
= −27x4 x2 = −9x4 and x3 = −2x4 which is closely related to the fourth column of c .
x = -c(:,4);
x(4) = 1
x =
-27
-9
2
1
Column Space
Column space
The column space of an m × n matrix A is the subspace of Rm spanned by the columns of A .
A
rref(A)
A =
4 -18 -21
-4 30 33
0 1 1
ans =
1.0000 0 -0.7500
0 1.0000 1.0000
0 0 0
The matrix A has two linearly independent columns corresponding to its two pivots as shown when converted to
RREF.
v1 = A(:,1)
v2 = A(:,2)
Print to PDF
v1 =
4
-4
0
v2 =
-18
30
1
https://straightdraw.github.io/Linear/ch2/6.html 3/4
3/4/24, 8:36 PM 2.6 Subspaces — Linear Algebra with MATLAB
⎧ ⎡
⎪ 4 −18 ⎫
⎤ ⎡ ⎤ ⎪
Col(A) = Span ⎨ ⎢ −4 ⎥ , ⎢ 30 ⎥ ⎬
⎩
⎪ ⎣ ⎦ ⎣ ⎦ ⎭
⎪
0 1
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch2/6.html 4/4
3/4/24, 8:36 PM 2.6.1 Lab 4 — Linear Algebra with MATLAB
2.6.1 Lab 4
First:
⎧ −1 −2 4 0
⎪ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤⎫⎪
⎪ ⎪
⎪ ⎪
⎢ 0⎥ ⎢ 15 ⎥ ⎢ 9⎥ ⎢ 10 ⎥
⃗ = ⎢
⎨v1 ⃗ = ⎢
⎥ , v2 ⃗ = ⎢
⎥ , v3 ⃗
⎥ , v4 = ⎢ ⎥⎬
⎢ 0⎥ ⎢ −6 ⎥ ⎢ −3 ⎥ ⎢ −4 ⎥
⎪ ⎪
⎪
⎩ ⎪
⎭
⎪ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦⎪
0 3 5 2
v1 = [-1 ; 0 ; 0 ; 0 ] ;
v2 = [-2 ; 15 ; -6 ; 3 ] ;
v3 = [4 ; 9 ; -3 ; 5 ] ;
v4 = [0 ; 10 ; -4 ; 2 ] ;
⎧ 5 −1 2 1
⎪ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤⎫⎪
⎪ ⎪
⎪ ⎪
⎢ 0⎥ ⎢ 2⎥ ⎢ −2 ⎥ ⎢ −3 ⎥
Second: $⎨ v 5⃗ = ⎢ ⃗ = ⎢
⎥ , v6 ⃗ = ⎢
⎥ , v7 ⃗
⎥ , v8 = ⎢ ⎥⎬ $
⎢ 0⎥ ⎢ −2 ⎥ ⎢ 7⎥ ⎢ 5 ⎥⎪
⎪
⎪
⎩ ⎪
⎭
⎪ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦⎪
0 0 15 8
v5 = [5 ; 0 ; 0 ; 0 ] ;
v6 = [-1 ; 2 ; -2 ; 0 ] ;
v7 = [2 ; -2 ; 7 ; 15 ] ;
v8 = [1 ; -3 ; 5 ; 8 ] ;
First:
⎧ 0 4 7 3
⎪ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤⎫⎪
⎪ ⎪
⎪ ⎪
⎢ 9⎥ ⎢ −11 ⎥ ⎢ −17 ⎥ ⎢ 12 ⎥
⃗ = ⎢
⎨ x1 ⎥ , x2
⃗ = ⎢ ⎥ , x3
⃗ = ⎢ ⎥ , x4
⃗ = ⎢ ⎥⎬
⎢ −1 ⎥ ⎢ 1⎥ ⎢ 2⎥ ⎢ −1 ⎥
⎪ ⎪
⎪
⎩ ⎪
⎭
⎪ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦⎪
1 −1 −2 1
x1 = [0 ; 9 ; -1 ; 1 ] ;
x2 = [4 ; -11 ; 1 ; -1 ] ;
x3 = [7 ; -17 ; 2 ; -2 ] ;
x4 = [3 ; 12 ; -1 ; 1 ] ;
Second:
⎧ −1 −1 −1 −1
⎪ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤⎫⎪
⎪ ⎪
⎪ ⎪
⎢ −2 ⎥ ⎢ 5⎥ ⎢ −12 ⎥ ⎢ −15 ⎥
⃗ = ⎢
⎨ x5 ⎥ , x6
⃗ = ⎢ ⎥ , x7
⃗ = ⎢ ⎥ , x8
⃗ = ⎢ ⎥⎬
⎢ −1 ⎥ ⎢ −2 ⎥ ⎢ 0 ⎥ ⎢ 0 ⎥⎪
⎪
⎪
⎩ ⎪
⎭
⎪ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦⎪
−2 2 −9 −11
https://straightdraw.github.io/Linear/ch2/06/1.html 1/3
3/4/24, 8:36 PM 2.6.1 Lab 4 — Linear Algebra with MATLAB
x5 = [-1 ; -2 ; -1 ; -2 ] ;
x6 = [-1 ; 5 ; -2 ; 2 ] ;
x7 = [-1 ; -12 ; 0 ; -9 ] ;
x8 = [-1 ; -15 ; 0 ; -11 ] ;
First:
⎧ −1 49 34 −44
⎪ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤⎫⎪
⎪ ⎪
⎪ ⎪
⎢ 3⎥ ⎢ −122 ⎥ ⎢ −82 ⎥ ⎢ 247 ⎥
⃗ = ⎢
⎨y 1 ⎥ , y2
⃗ = ⎢ ⎥ , y3
⃗ = ⎢ ⎥ , y4
⃗ = ⎢ ⎥⎬
⎢ 1⎥ ⎢ −49 ⎥ ⎢ −34 ⎥ ⎢ 84 ⎥ ⎪
⎪
⎪
⎩ ⎪
⎭
⎪ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦⎪
0 5 4 −1
y1 = [-1 ; 3 ; 1 ; 0 ] ;
y2 = [49 ; -122 ; -49 ; 5 ] ;
y3 = [34 ; -82 ; -34 ; 4 ] ;
y4 = [-44 ; 247 ; 84 ; -1 ] ;
Second:
⎧ 12 0 19 76
⎪ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤⎫⎪
⎪ ⎪
⎪ ⎪
⎢ 0⎥ ⎢ 4⎥ ⎢ −3 ⎥ ⎢ −6 ⎥
⎨y ⃗ = ⎢ ⎥ , y6
⃗ = ⎢ ⎥ , v3
⃗ = ⎢ ⎥ , v4
⃗ = ⎢ ⎥⎬
5
⎢ 0⎥ ⎢ 0⎥ ⎢ 1⎥ ⎢ 5 ⎥⎪
⎪
⎪
⎩ ⎪
⎭
⎪ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦⎪
12 0 19 77
y5 = [12 ; 0 ; 0 ; 12 ] ;
y6 = [0 ; 4 ; 0 ; 0 ] ;
y7 = [19 ; -3 ; 1 ; 19 ] ;
y8 = [76 ; -6 ; 5 ; 77 ] ;
1 2 1 1
⎡ ⎤
A = ⎢ −2 1 1 −3 ⎥
⎣ ⎦
1 −3 −1 3
A = [1 2 1 1 ; -2 1 1 -3 ; 1 -3 -1 3 ] ;
2 6 −4 11
⎡ ⎤
D = ⎢ 0 −8 5 −14 ⎥
⎣ ⎦
0 12 −7 19
D = [2 6 -4 11 ; 0 -8 5 -14 ; 0 12 -7 19 ] ;
https://straightdraw.github.io/Linear/ch2/06/1.html 2/3
3/4/24, 8:36 PM 2.6.1 Lab 4 — Linear Algebra with MATLAB
1 8 5 4
⎡ ⎤
J = ⎢ 2 91 40 38 ⎥
⎣ ⎦
−2 −16 −9 −10
J = [1 8 5 4 ; 2 91 40 38 ; -2 -16 -9 -10 ] ;
B through G, do B.
H through Q, do H.
R through Z, do R.
A pick any of the three.
2 2 5 1
⎡ ⎤
⎢ −2 −2 −5 −2 ⎥
B = ⎢ ⎥
⎢ 0 0 0 −1 ⎥
⎣ ⎦
2 2 5 1
B = [2 2 5 1 ; -2 -2 -5 -2 ; 0 0 0 -1 ; 2 2 5 1 ] ;
0 −2 −1 5
⎡ ⎤
Print to PDF
⎢ 0 −2 −1 5 ⎥
H = ⎢ ⎥
⎢ 5 1 −2 0 ⎥
⎣ ⎦
0 1 1 −1
H = [0 -2 -1 5 ; 0 -2 -1 5 ; 5 1 -2 0 ; 0 1 1 -1 ] ;
6 6 −12 37 −8
⎡ ⎤
R = ⎢ −4 6 −2 −7 3⎥
⎣ ⎦
2 −2 0 5 −2
R = [-3 2 2 0 ; -1 -1 1 4 ; -3 -3 3 17 ; 0 0 0 -1 ] ;
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch2/06/1.html 3/3
3/4/24, 8:37 PM 2.7 Basis and Dimension — Linear Algebra with MATLAB
Basis
Let V be a subspace of Rn. A basis of V is a set of vectors {v 1⃗ , v 2⃗ , … , v m
⃗ } ∈ V such that:
1. V ⃗ , v2
= Span{v 1 ⃗ , … , vm
⃗ } , and
2. the set {v 1⃗ , v 2⃗ , … , v m
⃗ } is linearly independent.
Finding a Basis
−1 −6 −4
⎡ ⎤ ⎡ ⎤ ⎡ ⎤
⃗ = ⎢ −4 ⎥ , v 2
v1 ⃗ = ⎢ −20 ⎥ , v 3
⃗ = ⎢ −13 ⎥
⎣ ⎦ ⎣ ⎦ ⎣ ⎦
1 6 4
v1 =
-1
-4
1
v2 =
-6
-20
6
v3 =
-4
-13
4
To find the basis for a Span of a set of vectors, we need to know how many of the vectors are linearly
independent. Let’s row reduce M .
rref(M)
ans =
1.0000 0 -0.5000
0 1.0000 0.7500
0 0 0
From the RREF of M , we can determine the linear dependence relation which indicates
1 3
⃗ =
v3 ⃗ −
v1 ⃗
v2
2 4
https://straightdraw.github.io/Linear/ch2/7.html 1/3
3/4/24, 8:37 PM 2.7 Basis and Dimension — Linear Algebra with MATLAB
and the Span for these vectors is a two dimensional subspace. This means that the vectors v 1⃗ and v 2⃗ form a basis
for the Span .
⎧ −1 −6
⎪⎡ ⎤ ⎡ ⎤⎫
⎪
B = ⎨ ⎢ −4 ⎥ , ⎢ −20 ⎥ ⎬
⎩⎣
⎪ ⎦ ⎣ ⎦⎪⎭
1 6
As the Margalit text points out, there are infinitely many bases for this subspace, but the Span of each of these
will be identical.
R = [8 -4 -4 0 11 ; -2 5 3 4 3 ; 6 -3 -3 0 7 ; 0 -4 -2 -4 -5 ]
R =
8 -4 -4 0 11
-2 5 3 4 3
6 -3 -3 0 7
0 -4 -2 -4 -5
Since the vectors live in R4 , we can have at most four linearly independent vectors and, correspondingly, a 4-
dimensional subspace.
rref(R)
ans =
Upon row reducing, we find three pivots, so we know that vectors v 3⃗ , v 4⃗ can be written as linear combinations of
the other three. The vectors that correpond to the pivot columns are linearly independent and form a basis for the
Span of this set of vectors.
⎧⎡ 8 −4 11
⎪ ⎤ ⎡ ⎤ ⎡ ⎤⎫⎪
⎪ ⎪
⎪ ⎪
⎢ −2 ⎥ ⎢ 5⎥ ⎢ 3 ⎥
B = ⎨⎢ ⎥,⎢ ⎥,⎢ ⎥⎬
⎢ 6 ⎥ ⎢ −3 ⎥ ⎢ 7 ⎥
⎪
⎪ ⎪
⎪
⎩
⎪⎣ ⎭
⎦⎪
0
⎦ ⎣
−4
⎦ ⎣
−5 Print to PDF
So the column space for matrix R from Example 2 has the same basis as the span of the vectors.
vector form.
https://straightdraw.github.io/Linear/ch2/7.html 2/3
3/4/24, 8:37 PM 2.7 Basis and Dimension — Linear Algebra with MATLAB
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch2/7.html 3/3
3/4/24, 8:37 PM 2.8 Bases as Coordinate Systems — Linear Algebra with MATLAB
The standard basis vectors are the columns of the n × n identity matrices which are generally referred to as In .
I2 = eye(2)
I2 =
1 0
0 1
e1 = I2(:,1)
e1 =
1
0
e2 = I2(:,2)
e2 =
0
1
I3 = eye(3)
I3 =
1 0 0
0 1 0
0 0 1
Notice that we still use the vectors e 1⃗ and e 2⃗ even though we are referring to 3-component vectors now.
e1 = I3(:,1)
e1 =
1
0
0
e2 = I3(:,2)
e2 =
0
1
0
e3 = I3(:,3)
https://straightdraw.github.io/Linear/ch2/8.html 1/4
3/4/24, 8:37 PM 2.8 Bases as Coordinate Systems — Linear Algebra with MATLAB
e3 =
0
0
1
Alternate basis B
Any set of linearly independent vectors {v 1⃗ , v 2⃗ , … , v m
⃗ } may serve as a basis for the subset it spans. For
example, suppose that the vectors {v 1⃗ , v 2⃗ , v 3⃗ } all live in R3 and that they are linearly independent. Then, we can
use
⃗ , v2
B = {v 1 ⃗ , v3
⃗ }
as the basis for R3 . To see why, let’s create a linearly independent set.
−1 1 −1 −3
⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤
⃗ = ⎢
v1 1 ⎥ , v2
⃗ = ⎢ 9 ⎥ , v3
⃗ = ⎢ −1 ⎥ and w⃗ = ⎢ 5⎥
⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦
0 5 −2 2
B = [-1 1 -1 ; 1 9 -1 ; 0 5 -2 ]
B =
-1 1 -1
1 9 -1
0 5 -2
rref(B)
ans =
1 0 0
0 1 0
0 0 1
Because we have 3 pivots, we know the Span{v 1⃗ , v 2⃗ , v 3⃗ } is a 3-dimensional subspace of R3 , and the only 3D
subspace of R3 is R3 itself.
⃗ + c2 v2
c1 v1 ⃗ + c3 v3
⃗ = w⃗
Bc ⃗ = w⃗
where the matrix B has as its columns the vectors from the basis B . To do so, we row reduce the augmented
matrix.
https://straightdraw.github.io/Linear/ch2/8.html 2/4
3/4/24, 8:37 PM 2.8 Bases as Coordinate Systems — Linear Algebra with MATLAB
B = [-1 1 -1 ; 1 9 -1 ; 0 5 -2 ]
w = [-3 ; 5 ; 2]
B =
-1 1 -1
1 9 -1
0 5 -2
w =
-3
5
2
A = [ B, w ]
A =
-1 1 -1 -3
1 9 -1 5
0 5 -2 2
rref(A)
ans =
1 0 0 4
0 1 0 0
0 0 1 -1
The linear dependence relation tells use the linear combination of the basis vectors that will produce w⃗ .
−4
⎡ ⎤
−4v 1
⃗ + (0)v 2
⃗ + v3
⃗ = w ⟹ c⃗ = ⎢ 0⎥
⎣ ⎦
1
b1 = B(:,1)
b3 = B(:,3)
-4 * b1 + b3
b1 =
-1
1
0
b3 =
-1
-1
-2
ans =
3
-5
-2
The B -coordinates of the vector w⃗ are the coefficients of the linear dependence relation. This means we have
−4
⎡ ⎤
w⃗ B = ⎢ 0⎥
⎣ ⎦
1
B
https://straightdraw.github.io/Linear/ch2/8.html 3/4
3/4/24, 8:37 PM 2.8 Bases as Coordinate Systems — Linear Algebra with MATLAB
where the subscript indicates the corrdinates used to represent the vector. To convert the vector back to standard
coordinates, we simply multiply the matrix B by the coordinates from the linear dependence relation.
B * [ 4 ; 0 ; -1]
ans =
-3
5
2
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch2/8.html 4/4
3/4/24, 8:37 PM 2.9 The Rank Theorem — Linear Algebra with MATLAB
We will repeat the following important theorem from the Margalit textbook.
Rank of a matrix A
The dimension of the column space of A is the *rank+ of A .
Nullity of a matrix A
The dimension of the null space of A is the nullity of A .
Rank Theorem The rank of matrix A plus the nullity of A equals the number of columns in A . If A is an m × n
matrix, then
rank + nullity = n
M =
-4 3 25 11
-12 7 81 35
-2 2 11 5
ans =
The matrix M has two pivots, so it’s column space is a 2-dimensional subspace of R3 and it’s rank equals 2. There
are two free variables, so the null space is a 2-dimensonial subspace of R4 . The solution vector
x1
⎡ ⎤
⎢ x2 ⎥
x⃗ = ⎢ ⎥
⎢x ⎥
3
⎣ ⎦
x4
has four components. Since there are two free variables, a basis for the null space will require two vectors, and
hence the nullity of A also equals 2.
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch2/9.html 1/1
3/4/24, 8:38 PM 2.9.1 Lab 5 — Linear Algebra with MATLAB
0 0 0 −1
⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤
⎢ 0⎥ ⎢ −1 ⎥ ⎢ 3⎥ ⎢ 2⎥
⃗ = ⎢
v1 ⃗ = ⎢
⎥ , v2 ⃗ = ⎢
⎥ , v3 ⃗ = ⎢
⎥ , v4 ⎥
⎢ 0⎥ ⎢ 1⎥ ⎢ −3 ⎥ ⎢ −4 ⎥
⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦
1 1 4 4
v1 = [0 ; 0 ; 0 ; 1 ];
v2 = [0 ; -1 ; 1 ; 1 ];
v3 = [0 ; 3 ; -3 ; 4 ];
v4 = [-1 ; 2 ; -4 ; 4 ];
4 1 1 −1
⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤
⎢ −4 ⎥ ⎢ −1 ⎥ ⎢ −5 ⎥ ⎢ 21 ⎥
⃗ = ⎢
x1 ⃗ = ⎢
⎥ , x2 ⃗ = ⎢
⎥ , x3 ⃗ = ⎢
⎥ , x4 ⎥
⎢ 0⎥ ⎢ 0⎥ ⎢ 0⎥ ⎢ 1⎥
⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦
0 0 0 1
x1 = [4 ; -4 ; 0 ; 0 ];
x2 = [1 ; -1 ; 0 ; 0 ];
x3 = [1 ; -5 ; 0 ; 0 ];
x4 = [-1 ; 21 ; 1 ; 1 ];
−4 2 6 19
⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤
⎢ 0⎥ ⎢ 3⎥ ⎢ −2 ⎥ ⎢ 5⎥
⃗ = ⎢
y1 ⃗ = ⎢
⎥ , y2 ⃗ = ⎢
⎥ , y3 ⃗ = ⎢
⎥ , y4 ⎥
⎢ 0 ⎥ ⎢ 0 ⎥ ⎢ 0 ⎥ ⎢ 1⎥
⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦
−4 2 6 19
y1 = [-4 ; 0 ; 0 ; -4 ];
y2 = [2 ; 3 ; 0 ; 2 ];
y3 = [6 ; -2 ; 0 ; 6 ];
y4 = [19 ; 5 ; 1 ; 19 ];
A through D, do A.
D through J, do D.
J through Z, do J.
https://straightdraw.github.io/Linear/ch2/09/1.html 1/3
3/4/24, 8:38 PM 2.9.1 Lab 5 — Linear Algebra with MATLAB
1 23 8
⎡ ⎤
A = ⎢ 1 18 5⎥
⎣ ⎦
0 0 1
A = [1 23 8 ; 1 18 5 ; 0 0 1 ];
1 10 2
⎡ ⎤
D = ⎢ 0 0 1 ⎥
⎣ ⎦
0 1 −2
D = [1 10 2 ; 0 0 1 ; 0 1 -2 ];
−6 5 −12
⎡ ⎤
J = ⎢ 0 1 1⎥
⎣ ⎦
8 −6 17
J = [-6 5 -12 ; 0 1 1 ; 8 -6 17 ];
8
w⃗ = [ ]
−2
B through G, do Set 1.
H through Q, Set 2.
R through Z, Set 3.
A pick any of the three.
Set 1
3 4
⃗ ⃗
b1 = [ ] , b2 = [ ]
1 1
B = [3 4 ; 1 1 ];
Set 2
−3 −7
⃗ ⃗
b1 = [ ] , b2 = [ ]
3 2
B = [-3 -7 ; 3 2 ];
Set 3
−8 3
⃗ ⃗
b1 = [ ] , b2 = [ ]
6 −1
B= [-8 3 ; 6 -1 ];
https://straightdraw.github.io/Linear/ch2/09/1.html 2/3
3/4/24, 8:38 PM 2.9.1 Lab 5 — Linear Algebra with MATLAB
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch2/09/1.html 3/3
3/4/24, 8:38 PM 3.1 Matrix Transformations — Linear Algebra with MATLAB
Functions
The Margalit text suggests thinking first of a function like
2
f (x) = x
except that we are now going to use a vector x⃗ as the input. Our output will be a vector y ⃗, too. A transformation
looks very similar.
⃗ = y⃗
T (x )
Example
Consider the transformation T ⃗
(x ) accomplished by mutliplication of the vector x⃗ by the matrix
−2 1 3 1
A = [ ]
−2 1 2 0
A = [-2 1 3 1 ; -2 1 2 0 ]
A =
-2 1 3 1
-2 1 2 0
Domain
The domain of T ⃗
(x ) consists of all possible vectors that can be multiplied by A , in this case, all possible 4-
component vectors. The domain for T ⃗
(x ) is R4 .
x1 = [1 ; 0 ; -3 ; 2];
x2 = [4 ; 3 ; -2 ; -1];
A * x1
A * x2
ans =
-9
-8
ans =
-12
-9
Codomain
When we multiply Ax,⃗ the output is a 2-component vector, so the codomain is R2 . The range is subset of the
codomain. The codomain is the vector space where the vectors live. The range is a subset of that vector space.
Sometime the range subset is the entire codomain. If so, the transforamtion is called onto.
https://straightdraw.github.io/Linear/ch3/1.html 1/2
3/4/24, 8:38 PM 3.1 Matrix Transformations — Linear Algebra with MATLAB
−2
y⃗ = [ ]
1
y = [-2 ; 1]
rref([A,y])
y =
Print to PDF
-2
1
ans =
Boolean Value
e = false
f = true
List
Number
a=1
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch3/1.html 2/2
3/4/24, 8:39 PM 3.2 One-to-one and Onto Transformations — Linear Algebra with MATLAB
⃗ = y⃗
T (x )
based on the n × m matrix A always maps from the domain Rm into the range Rn . The vectors x⃗ in the domain,
to be able to be multiplied in the order Ax⃗ must have the same number of components as the columns of A , which
is m. The vectors y ⃗ in the range will have n components because n dot products will be needed.
We reproduce a theorem from Margalit to show what we can do with MATLAB to verify a matrix transformation is
one-to-one.
1. T is one-to-one.
2. For every b ⃗ ∈ R
m
, the equation T ⃗ = b
(x )
⃗
has at most one solution.
3. For every b ⃗ ∈ R
n
, the equation Ax⃗ = b
⃗
has a unique solution or is inconsistent.
4. Ax⃗ = 0
⃗ has only the trivial solution.
5. The columns of A are linearly independent.
6. A has a pivot in every column.
7. The range of T has dimension n .
To verify a matrix transformation is one-to-one, we can use option 6: row-reduce A to determine if every column
corresponds to a pivot position.
Examples
Consider the transformations corresponding to the following matrices:
3 −11 0 −1 1
⎡ ⎤ ⎡ ⎤
A = ⎢ 0 1 ⎥, B = ⎢ 2 3 5⎥
⎣ ⎦ ⎣ ⎦
0 1 −4 9 −24
0 0 −1 1
⎡ ⎤
4 2 23 10 8
⎡ ⎤
⎢ 1 4 1 1⎥
C = ⎢ ⎥, D = ⎢ −4 −2 −18 −7 −6 ⎥
⎢ 1 4 −2 6⎥ ⎣ ⎦
−16 −8 −57 −18 −19
⎣ ⎦
1 4 −2 4
It should be clear right away that the wide matrix D could never be associated with a one-to-one transformation.
There is no way it could have pivots in all five columns since only three pivots are possible. Let’s check on the
others.
A = [3 -11 ; 0 1 ; 0 1 ];
B = [0 -1 1 ; 2 3 5 ; -4 9 -24 ];
C = [0 0 -1 1 ; 1 4 1 1 ; 1 4 -2 6 ; 1 4 -2 4 ];
D = [4 2 23 10 8 ; -4 -2 -18 -7 -6 ; -16 -8 -57 -18 -19 ];
rref(A)
rref(B)
https://straightdraw.github.io/Linear/ch3/2.html 1/3
3/4/24, 8:39 PM 3.2 One-to-one and Onto Transformations — Linear Algebra with MATLAB
ans =
1 0
0 1
0 0
ans =
1 0 0
0 1 0
0 0 1
Both matrices A and B have a pivot in each column, so their corresponding transformations will be one-to-one.
rref(C)
ans =
1 4 0 0
0 0 1 0
0 0 0 1
0 0 0 0
While it certainly would be possible for a 4 × 4 matrix to be one-to-one, this one is not. It has only three pivots.
1. T is onto.
2. T ⃗ = b
(x )
⃗
has at least one solution for every b ⃗ ∈ R
m
.
3. Ax⃗ = b
⃗
is consistent for every b ⃗
∈ R
m
A = [3 -11 ; 0 1 ; 0 1 ];
B = [0 -1 1 ; 2 3 5 ; -4 9 -24 ]; Note
C = [0 0 -1 1 ; 1 4 1 1 ; 1 4 -2 6 ; 1 4 -2 4 ];
D = [4 2 23 10 8 ; -4 -2 -18 -7 -6 ; -16 -8 -57 -18 -19 ]; A square matrix M is both one-to-one
neither.
rref(A)
ans =
1 0
0 1
0 0
Of course, there is no way for the tall matrix A to be onto since it can have at most 2 pivots.
rref(B)
ans =
1 0 0
0 1 0
0 0 1
rref(D)
ans =
https://straightdraw.github.io/Linear/ch3/2.html 2/3
3/4/24, 8:39 PM 3.2 One-to-one and Onto Transformations — Linear Algebra with MATLAB
The transformations associated with matrices B and D are onto because the matrices have pivots in every row.
rref(C)
ans =
1 4 0 0
0 0 1 0
0 0 0 1
0 0 0 0
The transformation associated with matrix C is not onto because not every row has a pivot.
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch3/2.html 3/3
3/4/24, 8:39 PM 3.3 Linear Transformations — Linear Algebra with MATLAB
Matrix Transformations
All linear transformations of vector spaces are matrix transformations. Let’s specify exactly what we mean by
terms like standard matrix.
Standard Matrix
The matrix associated with the linear transformation so that
⃗ = Ax ⃗
T (x )
Linear Transformation
A transformation T : R
n
→ R
m
, for all vectors u,⃗ v ⃗ ∈ R
n
and all scalars c , satisfies
T (u ⃗ + v )
⃗ = T (u )
⃗ + T (v )
⃗
⃗ = cT (u)
T (cu) ⃗
The transformation is the same regardless of whether we add the vectors and transform the sum or transform the
vectors then sum them. The same is true for scalar products.
Note
The zero vector is always mapped to the zero vector by a linear transformation.
⃗ ⃗
T (0 ) = 0
Tip
Find where the standard basis vectors are mapped, and you have found the standard matrix of the linear
transformation.
To find what matrix is associated with a linear transformation, we find where the standard basis vectors are
mapped. If the transformation
T (x )
⃗ = Ax ⃗
⃗ ), T (e 2
A = [T (e 1 ⃗ ), ⋯ , T (e m
⃗ )]
Reflections in R
2
https://straightdraw.github.io/Linear/ch3/3.html 1/4
3/4/24, 8:39 PM 3.3 Linear Transformations — Linear Algebra with MATLAB
1 1
⃗ ) = T ([
T (e 1 ]) = [ ]
0 0
but
0 0
⃗ ) = T ([
T (e 2 ]) = [ ]
1 −1
1 0
A = [ ]
0 −1
0 0
⃗ ) = T ([
T (e 2 ]) = [ ]
1 1
but
1 −1
⃗ ) = T ([
T (e 1 ]) = [ ]
0 0
−1 0
A = [ ]
0 1
1 0
⃗ = A1 v ⃗ = [
T1 (v ) ] v⃗
0 −1
and
−1 0
⃗ = A2 v ⃗ = [
T2 (v ) ] v⃗
0 1
The first transformation followed by the second is a composition of the transformation functions where
⃗
T2 (T1 (v )) = A2 A1 v ⃗
1 0 −1 0 −1 0
A2 A1 = [ ][ ] = [ ]
0 −1 0 1 0 −1
https://straightdraw.github.io/Linear/ch3/3.html 2/4
3/4/24, 8:39 PM 3.3 Linear Transformations — Linear Algebra with MATLAB
Warning
Do not be fooled by this case where A1 A2 = A2 A1 . Multiplying in the incorrect order usually
generates an incorrect standard matrix for the transformation.
Scaling in R
2
Horizontal scaling
For a non-zero k ∈ R , horizontal scaling by a factor of k sends e 1⃗ to ke 1⃗
1 k
⃗ ) = T ([
T (e 1 ]) = [ ]
0 0
k 0
A = [ ]
0 1
Vertical scaling
The same reasoning applies, and
1 0
A = [ ]
0 k
Rotations in R
2
We can only accomplish certain rotations using the approach shown above. In general, a rotation by θ is given by
cos θ − sin θ
⃗ = [
Rθ (v ) ]
sin θ cos θ
Summary
You should know how to find the standard matrix of a transformation, including compositions of multiple
transformations. Matrix multiplication and composition of linear transformation will be covered in full detail in the
next section.
Example
Suppose we wish to find the standard matrix for a transformation that (1) stretches vertically by a factor of 4, then
(2) rotates by 270∘ and finally (3) reflects across the x-axis.
1 0
A1 = [ ]
0 4
https://straightdraw.github.io/Linear/ch3/3.html 3/4
3/4/24, 8:39 PM 3.3 Linear Transformations — Linear Algebra with MATLAB
1 0
A3 = [ ]
0 −1
A1 = [ 1 0 ; 0 4 ]
A2 = [ cosd(270) -sind(270) ; sind(270) cosd(270) ]
A3 = [ 1 0 ; 0 -1 ]
A1 =
1 0
0 4
Print to PDF
A2 =
0 1
-1 0
A3 =
1 0
0 -1
When we compose these standard matrices, we find the standard matrix for the entire transformation.
A = A3 * A2 * A1
A =
0 4
1 0
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch3/3.html 4/4
3/4/24, 8:39 PM 3.4 Matrix Multiplication — Linear Algebra with MATLAB
Dot products
In section 2.3, we learned that to multiply a matrix by a vector, as in Av ⃗, we take the dot product of each row of the
matrix with the vector v ⃗. For matrix mulitplication, we do much the same.
Recall
We refer to the entries of matrix A as aij where i is the row number and j is the column number of the
entry. The columns of matrix A , when referenced as vectors, are {a1⃗ , a2⃗ , … , ak⃗ }. We do not have any
standard notation for the rows of A .
We calculate matrix products entry by entry, with the row number and column number of the entry determining
the dot product we must calculate. For two matrices A and B for which the operations work, the entries c ij of
their product matrix C is the i^{th} row of A dotted with the j^{th} column of B.
c ij = Row(A, i) ⋅ Column(B, j)
Warning
The dot product requires input vectors of the same length which means that an n × m matrix A and an
r × k matrix B can only be multiplied if m = r .
2 2 5
⎡ ⎤
−1 6 −2 6 −12 20 52
⎡ ⎤ ⎡ ⎤
⎢ 1 −1 5⎥
AB = ⎢ 8 6 2 2⎥⎢ ⎥ = ⎢ −6 14 33 ⎥ = C
⎢ −1 4 5⎥
⎣ ⎦ ⎣ ⎦
−2 7 0 8 26 22 99
⎣ ⎦
−1 3 −2
(3 × 4)(4 × 3)
and we say the “inner dimensions” must be equal as, here, we have 4 = 4 .
Example
Let’s verify several of the entries in the 3 × 3 product matrix C .
A = [5 5 -1 1 ; 6 5 3 4 ; 1 -1 8 0 ] ;
B = [0 4 0 ; 2 0 1 ; 3 2 4 ; -1 4 0 ] ;
C = A * B
C =
6 22 1
15 46 17
22 20 31
dot(A(1,:),B(:,1))
https://straightdraw.github.io/Linear/ch3/4.html 1/3
3/4/24, 8:39 PM 3.4 Matrix Multiplication — Linear Algebra with MATLAB
ans =
dot(A(2,:),B(:,1))
ans =
15
dot(A(2,:),B(:,3))
ans =
17
1. Matrix multiplication is not commutative even when it is possible to multiply the matrices.
AB = AC ⇏ B = C
AB = 0
Addition of matrices
Addition of matrices occurs component-wise. For A + B = C , the matrix sum C has entries
c ij = aij + b ij
Example
Consider the sum of
0 6 1 5 1 11
⎡ ⎤ ⎡ ⎤ ⎡ ⎤
A + B = ⎢ 8 0 ⎥ + ⎢ −1 3⎥ = ⎢ 7 3⎥ = C
⎣ ⎦ ⎣ ⎦ ⎣ ⎦
0 1 8 5 8 6
A = [0 6 ; 8 0 ; 0 1 ] ;
B = [1 5 ; -1 3 ; 8 5 ] ;
A(1,1) + B(1,1)
https://straightdraw.github.io/Linear/ch3/4.html 2/3
3/4/24, 8:39 PM 3.4 Matrix Multiplication — Linear Algebra with MATLAB
ans =
A(2,2) + B(2,2)
ans =
A(3,1) + B(3,1)
ans =
Note
Since addition occurs component-wise, we can add matrix B to an n × m matrix A if and only B has
dimensions m × n.
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch3/4.html 3/3
3/4/24, 8:40 PM 3.5.1 Lab 6 — Linear Algebra with MATLAB
3.5.1 Lab 6
4 7 6
⎡ ⎤
J = ⎢ −2 −2 −1 ⎥
⎣ ⎦
4 4 1
J = [4 7 6 ; -2 -2 -1 ; 4 4 1 ] ;
4 7 6
⎡ ⎤
M = ⎢ −2 −2 −1 ⎥
⎣ ⎦
4 4 1
M = [4 7 6 ; -2 -2 -1 ; 4 4 1 ] ;
4 7 6
⎡ ⎤
S = ⎢ −2 −2 −1 ⎥
⎣ ⎦
4 4 1
S = [4 7 6 ; -2 -2 -1 ; 4 4 1 ] ;
A through D, do A ∗ B.
D through J, do D ∗ E.
J through Z, do J ∗ K .
−1 −2 −2
⎡ ⎤
0 8 1 5 ⎢ 7 4 0⎥
A = [ ] and B = ⎢ ⎥
3 1 8 −2 ⎢ 0 −2 5⎥
⎣ ⎦
0 −2 3
A = [0 8 1 5 ; 3 1 8 -2 ];
B = [-1 -2 -2 ; 7 4 0 ; 0 -2 5 ; 0 -2 3 ];
https://straightdraw.github.io/Linear/ch3/05/1.html 1/3
3/4/24, 8:40 PM 3.5.1 Lab 6 — Linear Algebra with MATLAB
−1 −2 −2
⎡ ⎤
−2 1 −1 −2 ⎢ 7 4 0⎥
D = [ ] and E = ⎢ ⎥
7 3 −2 6 ⎢ 0 −2 5⎥
⎣ ⎦
0 −2 3
D = [-2 1 -1 -2 ; 7 3 -2 6 ];
E = [-1 -2 -2 ; 7 4 0 ; 0 -2 5 ; 0 -2 3 ];
2 0
⎡ ⎤
−2 −1 1 −2 ⎢ 3 −1 ⎥
J = [ ] and K = ⎢ ⎥
−1 −2 7 0 ⎢ 3 6 ⎥
⎣ ⎦
8 2
J = [-2 -1 1 -2 ; -1 -2 7 0 ];
K = [2 0 ; 3 -1 ; 3 6 ; 8 2 ];
B through G, do B.
H through Q, do H.
R through Z, do R.
A pick any of the three.
6 −8 −5
⎡ ⎤
B = ⎢ 6 −7 −3 ⎥
⎣ ⎦
3 −4 −2
−3 −3 13 Print to PDF
⎡ ⎤
H = ⎢ −1 −2 3⎥
⎣ ⎦
1 2 −5
1 0 −8
⎡ ⎤
R = ⎢ −2 0 19 ⎥
⎣ ⎦
−2 −2 11
https://straightdraw.github.io/Linear/ch3/05/1.html 2/3
3/4/24, 8:40 PM 3.5.1 Lab 6 — Linear Algebra with MATLAB
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch3/05/1.html 3/3
3/4/24, 8:40 PM 3.6 Invertible Matrix Theorem — Linear Algebra with MATLAB
1. A is invertible.
2. A has n pivots.
3. Null(A) = 0
⃗
.
4. The columns of A are linearly independent.
5. The columns of A span Rn .
6. Ax⃗ = b
⃗
has a unique solution for each b in Rn .
7. The linear transformation T is invertible, specifically:
T is one-to-one.
T is onto.
Examples
Example 1
Determine if the linear transformation T is one-to-one. Is it onto? The standard matrix associated with T is
0 −2 −3 9
⎡ ⎤
⎢ 0 0 0 1⎥
A = ⎢ ⎥
⎢ −2 2 5 −15 ⎥
⎣ ⎦
1 −1 −2 7
A = [0 -2 -3 9 ; 0 0 0 1 ; -2 2 5 -15 ; 1 -1 -2 7 ];
rref(A)
ans =
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
With 4 pivots, we know the dimension of the null is zero and thus that the transformation is both one-to-one and
onto (invertible).
Example 2
Is the set of vectors a basis for R5 ?
⎧ 1 2 −2 2 2
⎪ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤⎫⎪
⎪
⎪ ⎪
⎪
⎪ ⎪
⎪
⎪ ⎢ −2 ⎥ ⎢ 0 ⎥ ⎢ −1 ⎥ ⎢ 1 ⎥ ⎢ 0 ⎥⎪⎪
⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥
⃗
⎨v1 = ⎢ 2 ⎥ , v2
⃗ = ⎢ 5 ⎥ , v⃗ = ⎢
3 3 ⎥ , v4
⃗ = ⎢ 2 ⎥ , v⃗
5 = ⎢ 3 ⎥⎬
⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥
⎪ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥ ⎢ ⎥⎪
⎪
⎪ ⎢ −1 ⎥ ⎢ 4 ⎥ ⎢ 3⎥ ⎢ 4 ⎥ ⎢ 1 ⎥⎪⎪
⎪
⎪
⎩
⎪
⎪
⎭
Print to PDF
⎪ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦⎪
3 5 4 3 2
https://straightdraw.github.io/Linear/ch3/6.html 1/2
3/4/24, 8:40 PM 3.6 Invertible Matrix Theorem — Linear Algebra with MATLAB
B = [1 2 -2 2 2 ; -2 0 -1 1 0 ; 2 5 3 2 3 ; -1 4 3 4 1 ; 3 5 4 3 2 ];
inv(B)
ans =
Since B is invertible, we know the columns are linearly independent and thus form a basis for R5 .
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch3/6.html 2/2
3/4/24, 8:43 PM 5.1 Eigenvalues and Eigenvectors — Linear Algebra with MATLAB
Example 1
Determine if the vector v ⃗ is an eigenvector of the matrix A where
15 0 24
⎡ ⎤
A = ⎢ 9 2 18 ⎥
⎣ ⎦
−8 0 −13
and
2
⎡ ⎤
v⃗ = ⎢ 3⎥
⎣ ⎦
−1
Solution. The question is whether the product Av ⃗ is equal to a scalar multiple of v ⃗, so we should just multiply and
check.
A = [15 0 24 ; 9 2 18 ; -8 0 -13 ];
v = [ 2 ; 3 ; -1 ]
v =
2
3
-1
A * v
ans =
6
6
-3
Example 2
Determine if the vector y ⃗ is an eigenvector of the matrix A where
−4 16 −14 22
⎡ ⎤
⎢ −6 20 −12 24 ⎥
B = ⎢ ⎥
⎢ 3 −8 9 −11 ⎥
⎣ ⎦
4 −12 8 −14
and
https://straightdraw.github.io/Linear/ch5/1.html 1/3
3/4/24, 8:43 PM 5.1 Eigenvalues and Eigenvectors — Linear Algebra with MATLAB
0
⎡ ⎤
⎢ −1 ⎥
y⃗ = ⎢ ⎥
⎢ 0⎥
⎣ ⎦
1
y =
1
-1
0
1
B*y
ans =
2
-2
0
2
Finding eignevalues
The eignevalues of a matrix A are possible values λ such that
Av ⃗ = λ v ⃗
Av ⃗ = λv ⃗
⃗
⟺ Av ⃗ − λ v ⃗ = 0
⃗
⟺ Av ⃗ − λI v ⃗ = 0
⃗
⟺ (A − λI )v ⃗ = 0
A − λI
and finding whether its null space has any nonzero vectors in it.
Example
Determine if λ = 3 is an eigenvalue for the matrix A where
A =
A = [3 0 0 ; -1 -13 15 ; -1 -12 14 ];
a = A - 3*eye(3)
a =
0 0 0
-1 -16 15
-1 -12 11
https://straightdraw.github.io/Linear/ch5/1.html 2/3
3/4/24, 8:43 PM 5.1 Eigenvalues and Eigenvectors — Linear Algebra with MATLAB
rref([a,zeros(3,1)])
ans =
1 0 1 0
0 1 -1 0
0 0 0 0
Because the homogeneous system is consistent, we know there are non-trivial solutions which means there are
non-zero vectors in the null space of A − λI . Thus, λ = 3 is an eigenvalue.
Example 3
To determine the associated eigenvector(s) once we know an eigenvalue, we write the solutions to the
homogeneous system in vector form.
x1 = −x3 −1
⎡ ⎤
x2 = x3 ⟹ v⃗ = ⎢ 1⎥
⎣ ⎦
x3 is free 1
The vector v ⃗ is an eigenvector of A associated with the eigenvalue λ = 3 , which can be verified by multiplication.
v = [ -1 ; 1 ; 1 ]
v =
-1
1
1
A * v
ans =
-3
3
3
A * v == 3 * v
ans =
1
1
1
Because equality holds (all 1’s in array), we know that we have found a eigenvalue-eigenvector pair.
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch5/1.html 3/3
3/4/24, 8:43 PM 5.2 The Characteristic Polynomial — Linear Algebra with MATLAB
p(λ) = det (A − λI )
Section 1
Finding eignevalues
The eignevalues of a matrix A are possible values λ such that
Av ⃗ = λ v ⃗
Av ⃗ = λv ⃗
⃗
⟺ Av ⃗ − λ v ⃗ = 0
⃗
⟺ Av ⃗ − λI v ⃗ = 0
⃗
⟺ (A − λI )v ⃗ = 0
3 0 0
⎡ ⎤
A = ⎢ 2 15 −14 ⎥
⎣ ⎦
2 12 −11
3 0 0 1 0 0
⎛⎡ ⎤ ⎡ ⎤⎞
3 0 0 λ 0 0
⎛⎡ ⎤ ⎡ ⎤⎞
= det ⎜⎢ 2 15 −14 ⎥ − ⎢ 0 λ 0 ⎥⎟
⎝⎣ ⎦ ⎣ ⎦⎠
2 12 −11 0 0 λ
3 − λ 0 0
⎛⎡ ⎤⎞
= det ⎜⎢ 2 15 − λ −14 ⎥ ⎟
⎝⎣ ⎦⎠
2 12 −11 − λ
We can expand across the top row which has two zero’s in it.
15 − λ −14
det(A − λI ) = (3 − λ) det ([ ]) − (0) + (0)
12 −11 − λ
Since the
https://straightdraw.github.io/Linear/ch5/2.html 1/9
3/4/24, 8:43 PM 5.2 The Characteristic Polynomial — Linear Algebra with MATLAB
15 − λ −14
det ([ ]) = (15 − λ)(−11 − λ) − (12)(−14)
12 −11 − λ
2
= λ + 11λ − 15λ − 165 + 168
2
= λ − 4λ + 3
2
p(λ) = (3 − λ)(λ − 4λ + 3)
3 2 2
= −λ + 4λ − 3λ + 3λ − 12λ + 9
3 2
= −λ + 7λ − 15λ + 9
A = [3 0 0 ; 2 15 -14 ; 2 12 -11 ];
charpoly(A)
ans =
1 -7 15 -9
2
p(λ) = (3 − λ)(λ − 4λ + 3)
2
= −(λ − 3) (λ − 1)
2
−(λ − 3) (λ − 1) = 0
λ = 3 and λ = 1
The multiplicity of the root λ = 3 is two. Eigenvalues also have multiplicties which match the multiplicities of
their corresponding roots. Since the multiplicity of the λ = 3 eigenvalue is two, we expect two different
eigenvectors to be associated with it.
As shown in section 1, to find an eigenvector related to λ = 1 , we must find the solutions (in vector form) to the
homogeneous system of equations:
A − λI = 0
Substituting λ = 1 :
A − I = 0
A - eye(3)
https://straightdraw.github.io/Linear/ch5/2.html 2/9
3/4/24, 8:43 PM 5.2 The Characteristic Polynomial — Linear Algebra with MATLAB
ans =
2 0 0
2 14 -14
2 12 -12
rref([A-eye(3),zeros(3,1)])
ans =
1 0 0 0
0 1 -1 0
0 0 0 0
x1 = 0
x2 = x3
So v ⃗ is an eigenvector.
0
⎡ ⎤
v⃗ = ⎢ 1 ⎥
⎣ ⎦
1
v = [0 ; 1 ; 1 ];
A*v
ans =
0
1
1
A*V == 1*v
Substituting λ = 3 into A − λI = 0
⃗
A − 3I = 0
A - 3 * eye(3)
ans =
0 0 0
2 12 -14
2 12 -14
Notice the rows of the matrix after the subtraction. This is typical when evaluating A − λI : having a row that is a
scalar multiple of another.
rref([A - 3*eye(3),zeros(3,1)])
https://straightdraw.github.io/Linear/ch5/2.html 3/9
3/4/24, 8:43 PM 5.2 The Characteristic Polynomial — Linear Algebra with MATLAB
ans =
1 6 -7 0
0 0 0 0
0 0 0 0
x1 = −6x2 + 7x3
−6 7
⎡ ⎤ ⎡ ⎤
v⃗ = ⎢ 1 ⎥ x2 + ⎢ 0 ⎥ x3
⎣ ⎦ ⎣ ⎦
0 1
where x2 , x3 are scalars. This means we have two eigenvectors associated with the eigenvalue λ = 3 which
makes sense. The λ = 3 eigenvalue has muliplicity 2. Let’s verify both vectors are eigenvectors. In MATLAB, the |
symbol means AND. The code block below will evaluate as True if and only if both v 1⃗ and v 2⃗ are eigenvectors of A .
A * v1 == 3*v1 | A * v2 == 3*v2
ans =
1
1
1
v1 = [-6 ; 1 ; 0]
A*v1
v1 =
-6
1
0
ans =
-18
3
0
v2 = [7 ; 0 ; 1]
A*v2
v2 =
7
0
1
ans =
21
0
3
Either way, we now know all three unique eigenvectors and the two eigenvalues for A .
https://straightdraw.github.io/Linear/ch5/2.html 4/9
3/4/24, 8:43 PM 5.2 The Characteristic Polynomial — Linear Algebra with MATLAB
−14 −78 26 66
⎡ ⎤
⎢ −2 −12 10 10 ⎥
B = ⎢ ⎥
⎢ 6 27 −4 −24 ⎥
⎣ ⎦
−9 −48 21 41
The charpoly function in MATLAB will produce the coefficients of the characteristic polynomial.
ans =
1 -11 38 -40 0
However, we need to use the syms function from the Symbolic Math Toolbox to have MATLAB do the work for us.
If you downloaded the software, you can repeat the process and select the correct toolbox. The download will be
quick - MATLAB will only download and install the new packages, not the whole program. If you’re working in
MATLAB online, you should not need to do anything different.
syms x
y = charpoly(B,x)
y =
polynomialReduce(y,x)
ans =
If we want to capture the quotient, too, we need to grab both the quotient and remainder of the division as shown.
[r,q] = polynomialReduce(y,x)
r =
q =
We know that any factors that divide q(x) evenly must be of the form:
x ± 1
x ± 2
x ± 4
x ± 5
x ± 8
https://straightdraw.github.io/Linear/ch5/2.html 5/9
3/4/24, 8:43 PM 5.2 The Characteristic Polynomial — Linear Algebra with MATLAB
r =
-630
q2 =
With a remainder of −630, we know that x + 5 is cleary not a factor. Let’s retry it with x − 5 .
r =
q2 =
x^2 - 6*x + 8
r =
q3 =
x - 2
If you were keeping track, you know that we have the following factors:
x − 2
x − 4
x − 5
As with any factoring problem, we can test our factored form by expanding.
z = x*(x-2)*(x-4)*(x-5)
z =
expand(z)
ans =
The expanded form of z matches y , so we have the correct factorization. This means that we now know all our
eigenvalues.
λ = {0, 2, 4, 5}
https://straightdraw.github.io/Linear/ch5/2.html 6/9
3/4/24, 8:43 PM 5.2 The Characteristic Polynomial — Linear Algebra with MATLAB
For λ = 0
rref([B, zeros(4,1)])
ans =
1.0000 0 0 -1.0000 0
0 1.0000 0 -0.6667 0
0 0 1.0000 0 0
0 0 0 0 0
1
⎡ ⎤
⎢ 2/3 ⎥
⃗
v0 = ⎢ ⎥
⎢ 0⎥
⎣ ⎦
1
3
⎡ ⎤
⎢ 2⎥
⃗ = ⎢
v0 ⎥
⎢ 0⎥
⎣ ⎦
3
For λ = 2
ans =
1 0 0 4 0
0 1 0 -2 0
0 0 1 -1 0
0 0 0 0 0
−4
⎡ ⎤
⎢ 2⎥
⃗ = ⎢
v2 ⎥
⎢ 1⎥
⎣ ⎦
1
For λ = 4
ans =
1.0000 0 0 0.6667 0
0 1.0000 0 -1.3333 0
0 0 1.0000 -1.0000 0
0 0 0 0 0
https://straightdraw.github.io/Linear/ch5/2.html 7/9
3/4/24, 8:43 PM 5.2 The Characteristic Polynomial — Linear Algebra with MATLAB
−2/3 −2
⎡ ⎤ ⎡ ⎤
⎢ 4/3 ⎥ ⎢ 4⎥
⃗
v4 = ⎢ ⎥ → ⎢ ⎥
⎢ ⎥
⎢ 1⎥ ⎢ 3⎥
⎣ ⎦ ⎣ ⎦
1 3
For λ = 5
ans =
1 0 0 2 0
0 1 0 -2 0
0 0 1 -2 0
0 0 0 0 0
−2
⎡ ⎤
⎢ 2⎥
⃗ = ⎢
v5 ⎥
⎢ 2⎥
⎣ ⎦
1
B v ⃗ = λv ⃗
v0 = [ 3 ; 2 ; 0 ; 3 ];
v2 = [ -4 ; 2 ; 1 ; 1 ];
v4 = [ -2 ; 4 ; 3 ; 3 ];
B * v0
Print to PDF
ans =
0
0
0
0
B * v2
ans =
-8
4
2
2
B * v4
ans =
-8
16
12
12
https://straightdraw.github.io/Linear/ch5/2.html 8/9
3/4/24, 8:43 PM 5.2 The Characteristic Polynomial — Linear Algebra with MATLAB
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch5/2.html 9/9
3/4/24, 8:44 PM 5.3 Similarity — Linear Algebra with MATLAB
Similar Matrices
Two matrices A and B are similar provided, for some invertible matrix P
−1
A = P BP
The rest of the Margalit section 5.3 is conceptual, not computational, but you should read and understand it.
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch5/3.html 1/1
3/4/24, 8:44 PM 5.4 Diagonalization — Linear Algebra with MATLAB
$$A = PDP^{-1}$$
where D is a diagonal matrix of eigenvalues and P has columns which are the corresponding eigenvectors.
Example
Diagonalize the matrix A .
−3 −7 −2
⎡ ⎤
A = ⎢ 0 −2 0⎥
⎣ ⎦
1 7 0
A = [-3 -7 -2 ; 0 -2 0 ; 1 7 0 ];
syms x
y = charpoly(A,x)
y =
Tip
We can ask the polynomialReduce function to return both quotient and remainder.
[r,q] = polynomialReduce(y,x-1)
r =
18
q =
x^2 + 6*x + 14
[r,q] = polynomialReduce(y,x+1)
https://straightdraw.github.io/Linear/ch5/4.html 1/4
3/4/24, 8:44 PM 5.4 Diagonalization — Linear Algebra with MATLAB
r =
q =
x^2 + 4*x + 4
2
z = (x + 1)(x + 2)
z = (x+1)*(x+2)^2
z =
(x + 1)*(x + 2)^2
expand(z)
ans =
Matrix D
The diagonal matrix we seek must include all the eigenvalues listed as many times as indicated by their
multiplicity.
−1 0 0
⎡ ⎤
D = ⎢ 0 −2 0⎥
⎣ ⎦
0 0 −2
D = [-1 0 0 ; 0 -2 0 ; 0 0 -2 ]
D =
-1 0 0
0 -2 0
0 0 -2
ans =
1 0 1 0
0 1 0 0
0 0 0 0
v1 = [ -1 ; 0 ; 1]
https://straightdraw.github.io/Linear/ch5/4.html 2/4
3/4/24, 8:44 PM 5.4 Diagonalization — Linear Algebra with MATLAB
v1 =
-1
0
1
ans =
1 7 2 0
0 0 0 0
0 0 0 0
v21 = [ -2 ; 0 ; 1];
v22 = [-7 ; 1 ; 0];
A * v1
ans =
1
0
-1
A * v21
ans =
4
0
-2
A * v22
ans =
14
-2
0
This means we have found and confirmed the eigenvectors for A , and we can construct the matrix P . We only
need to ensure that they are in the same order as their associated eigenvalues are in D .
P =
-1 -2 -7
0 0 1
1 1 0
P * D * inv(P)
ans =
-3 -7 -2
0 -2 0
1 7 0
https://straightdraw.github.io/Linear/ch5/4.html 3/4
3/4/24, 8:44 PM 5.4 Diagonalization — Linear Algebra with MATLAB
A =
-3 -7 -2
0 -2 0
1 7 0
A == P * D * inv(P)
ans =
1 1 1
1 1 1
1 1 1
−1 −2 −7
⎡ ⎤
P = ⎢ 0 0 1⎥
⎣ ⎦
1 1 0
−1 0 0
⎡ ⎤
D = ⎢ 0 −2 0⎥
⎣ ⎦
0 0 −2
Exercises
Determine if the following matrices are diagonlizable. If so, determine an invertible matrix C and diagonal matrix
D such that
−1
M = C DC
HW Question 1 HW Question 2
−4 3.5 −3 3 0 4
⎡ ⎤ ⎡ ⎤
A = ⎢ −6 6 −6 ⎥ B = ⎢ 2 −7 20 ⎥
⎣ ⎦ ⎣ ⎦
1 −0.5 0 1 −3 9
Solution Solution
By Robb Sinn
© Copyright 2021.
https://straightdraw.github.io/Linear/ch5/4.html 4/4