0% found this document useful (0 votes)
24 views

Combinepdf

Uploaded by

basitbasitahmad5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Combinepdf

Uploaded by

basitbasitahmad5
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 107

3/4/24, 8:40 PM 3.5.

1 Lab 6 — Linear Algebra with MATLAB

3.5.1 Lab 6

Part I. One-to-one Transformation


The given matrix is the standard matrix of a linear transformation. Determine if the linear transformation is one-
to-one.

If your birthday is in:

January through April, do matrix J .


May through August, do matrix M .
September through December, do matrix S .

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 ] ;

Part II. Matrix Multiplication


Using MATLAB’s dot function and not the multiplication operation, calculate the products of the following
matrices.

If your first name begins with:

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 ];

Part III: Inverse Matrix


Use row reduction (showing all steps) to find the inverse matrix.

If your last name begins with:

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

B = [6 -8 -5;6 -7 -3;3 -4 -2] ;

−3 −3 13 Print to PDF
⎡ ⎤

H = ⎢ −1 −2 3⎥
⎣ ⎦
1 2 −5

H = [-3 -3 13 ; -1 -2 3;1 2 -5] ;

1 0 −8
⎡ ⎤

R = ⎢ −2 0 19 ⎥
⎣ ⎦
−2 −2 11

R = [1 0 -8;-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

3.6 Invertible Matrix Theorem


Invertible Matrix Theorem (IMT). Let A be an n × n matrix, and let T : R
n
→ R
n
be the matrix transformation
⃗ = Ax ⃗
T (x ) . The following statements are equivalent:

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.

Using the IMT


We use the IMT all the time. Is a set of vectors a basis for Rn ? Combine them into a matrix and check to see if the
matrix is invertible. Is the linear transformation one-to-one? Verify the null space contains only the 0⃗. Does A
have an inverse? Row reduce and check how many pivots the matrix has.

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

We create the matrix B ⃗ ⃗ ⃗ ⃗ ⃗


= [b 1 , b 2 , b 3 , b 4 , b 5 ] and row reduce.

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 =

1.0000 -4.0000 0.0000 2.0000 -2.0000


-25.0000 110.0000 -7.0000 -61.0000 66.0000
10.0000 -45.0000 3.0000 25.0000 -27.0000
12.0000 -52.0000 3.0000 29.0000 -31.0000
23.0000 -101.0000 7.0000 56.0000 -61.0000

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

5.1 Eigenvalues and Eigenvectors


Eigenvector
An eigenvector of A is a nonzero vector v ⃗ in Rn such that Av ⃗ = λv ⃗ , for some scalar λ.
Eigenvalue
An eigenvalue of A is a scalar λ such that the equation Av ⃗ = λv ⃗ has a nontrivial solution.

Terminology. If Av ⃗ = λv ⃗ for some vector v ⃗ ≠ 0



, we say that λ is the eigenvalue for v ⃗, and that v ⃗ is an
eigenvector for λ.

Determining if a vector is an eigenvector of a


matrix
Print to PDF

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

By inspection, we see that Av ⃗ is not a scalar multiple of v ⃗, so v ⃗ is not an eigenvector of A .

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

Solution. Same question as above, so we multiply and check.

B = [-4 16 -14 22 ; -6 20 -12 24 ; 3 -8 9 -11 ; 4 -12 8 -14 ];


y = [1 ; -1 ; 0 ; 1 ]

y =

1
-1
0
1

B*y

ans =

2
-2
0
2

Clearly, By ⃗ = 2y ⃗ , so 2 is an eignevalue of matrix B, and y is its associated eigenvector.

Finding eignevalues
The eignevalues of a matrix A are possible values λ such that

Av ⃗ = λ v ⃗

which, after some algebra, is equivalent to solving a homogeneous set of equations.

Av ⃗ = λv ⃗


⟺ Av ⃗ − λ v ⃗ = 0


⟺ Av ⃗ − λI v ⃗ = 0


⟺ (A − λI )v ⃗ = 0

This means we can test eigenvalues by creating the matrix

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

To see if the null space is empty, we row-reduce the augmented matrix.

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

We are testing the specific equality:

A * v == 3 * v

ans =

3x1 logical array

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

5.2 The Characteristic Polynomial


Characteristic Polynomial
For an n × n matrix A , the characteristic polynomial of A is

p(λ) = det (A − λI )

Section 1

Finding eignevalues
The eignevalues of a matrix A are possible values λ such that

Av ⃗ = λ v ⃗

which, after some algebra, is equivalent to solving a homogeneous set of equations.

Av ⃗ = λv ⃗


⟺ Av ⃗ − λ v ⃗ = 0


⟺ Av ⃗ − λI v ⃗ = 0


⟺ (A − λI )v ⃗ = 0

Example: Eigenvalues and Eigenvectors


Find the eigenvalues and associated eigenvectors of matrix A .

3 0 0
⎡ ⎤

A = ⎢ 2 15 −14 ⎥
⎣ ⎦
2 12 −11

Example 1a: Find the characteristic polynomial of matrix A


The first step in finding the eigenvalues of matrix A is determining its characteric polynomial which means finding
the determinant of A − λI .

3 0 0 1 0 0
⎛⎡ ⎤ ⎡ ⎤⎞

det (A − λI ) = det ⎜⎢ 2 15 −14 ⎥ − λ ⎢ 0 1 0 ⎥⎟


⎝⎣ ⎦ ⎣ ⎦⎠
2 12 −11 0 0 1

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

we know the characteristic polynomial is the product

2
p(λ) = (3 − λ)(λ − 4λ + 3)

3 2 2
= −λ + 4λ − 3λ + 3λ − 12λ + 9
3 2
= −λ + 7λ − 15λ + 9

We can confirm using the MATLAB charpoly function.

A = [3 0 0 ; 2 15 -14 ; 2 12 -11 ];
charpoly(A)

ans =

1 -7 15 -9

Example 1b: Finding the eigenvalues


The coefficients from the charpoly function match our work if we mulitply through the expression by −1 which
will be mathematically correct since the eigenvalues of the matrix are the roots of the characteristic polynomial. In
fact, it was a waste of time algebraically to write p(λ) in expanded form since we actually need to set it equal to
zero and factor it.

2
p(λ) = (3 − λ)(λ − 4λ + 3)

= −(λ − 3)(λ − 3)(λ − 1)

2
= −(λ − 3) (λ − 1)

We set the characteristic polynomial equal to zero and solve.

2
−(λ − 3) (λ − 1) = 0

We have two eigenvalues.

λ = 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.

Example 1c: Finding the eigenvectors for λ = 1

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

We actually want to row reduce the augmented matrix [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

We can see that x3 is a free variable and that

x1 = 0

x2 = x3

So v ⃗ is an eigenvector.

0
⎡ ⎤

v⃗ = ⎢ 1 ⎥
⎣ ⎦
1

We can test by multiplying the matrix by the eigenvector.

v = [0 ; 1 ; 1 ];
A*v

ans =

0
1
1

We can also execute a code block with a conditional to check. Since

A*V == 1*v

evaluates True, we know that λ = 1 is eigenvalue of A .

Example 1d: Finding the eigenvectors for λ = 3

Substituting λ = 3 into A − λI = 0

A − 3I = 0

We actually want to row reduce the augmented matrix [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

A solution vector v ⃗ has the form

−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 =

3x1 logical array

1
1
1

For clarity, it helps to see the multiplication steps.

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 .

Example 2: Find eigenvalues and eigenvectors with


MATLAB
Find all the eigenvalues and eigenvectors for matrix B.

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.

B = [-14 -78 26 66 ; -2 -12 10 10 ; 6 27 -4 -24 ; -9 -48 21 41 ];


charpoly(B)

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 =

x^4 - 11*x^3 + 38*x^2 - 40*x

Using polynomialReduce function to determine fully factored


form of characteristic polynomial
The function polynomialReduce returns the remainder when one polynomial is divided by another.

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 =

x^3 - 11*x^2 + 38*x - 40

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

To experiment, let’s see if the factor x + 5 dvides q(x) evenly.

[r, q2] = polynomialReduce(q, x+5)

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 =

x^2 - 16*x + 118

With a remainder of −630, we know that x + 5 is cleary not a factor. Let’s retry it with x − 5 .

[r, q2] = polynomialReduce(q, x-5)

r =

q2 =

x^2 - 6*x + 8

[r,q3] = polynomialReduce(q2, x-4)

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 =

x*(x - 2)*(x - 4)*(x - 5)

expand(z)

ans =

x^4 - 11*x^3 + 38*x^2 - 40*x

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

Finding eigenvalues for each eigenvalue

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

With x4 free and x3 = 0 , solve to find eigenvector.

1
⎡ ⎤

⎢ 2/3 ⎥

v0 = ⎢ ⎥
⎢ 0⎥
⎣ ⎦
1

We are allowed to clear the denominators in the vector.

3
⎡ ⎤

⎢ 2⎥
⃗ = ⎢
v0 ⎥
⎢ 0⎥

⎣ ⎦
3

We will verify all of the eigenvectors at the end.

For λ = 2

rref([B - 2 * eye(4), zeros(4,1)])

ans =

1 0 0 4 0
0 1 0 -2 0
0 0 1 -1 0
0 0 0 0 0

With x4 free, solve to find eigenvector.

−4
⎡ ⎤

⎢ 2⎥
⃗ = ⎢
v2 ⎥
⎢ 1⎥
⎣ ⎦
1

For λ = 4

rref([B - 4 * eye(4), zeros(4,1)])

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

With x4 free, solve to find eigenvector and clear denominator.

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

rref([B - 5 * eye(4), zeros(4,1)])

ans =

1 0 0 2 0
0 1 0 -2 0
0 0 1 -2 0
0 0 0 0 0

With x4 free, solve to find eigenvector.

−2
⎡ ⎤

⎢ 2⎥
⃗ = ⎢
v5 ⎥
⎢ 2⎥
⎣ ⎦
1

We can now multiply the matrix B by each eigenvector to verify the

B v ⃗ = λv ⃗

property holds for each of them.

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

Thus, we have verified all the eigenvalues and associated eigenvectors.

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

5.3 Similarity Print to PDF

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

5.4 Diagonalization Print to PDF

The diagonalization of a matrix A , provided it exists, can be written as

$$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

Finding the eigenvalues and matrix D


As we found in section 5.2, the characteristic polynomial is found by calculating the determinant of the matrix
A − λI .

A = [-3 -7 -2 ; 0 -2 0 ; 1 7 0 ];
syms x
y = charpoly(A,x)

y =

x^3 + 5*x^2 + 8*x + 4

Testing factors for zero remainder using polynomialReduce function


MATLAB’s polynomialReduce function divides one polynomial by another of lesser degree returning the
remainder. This allows us to test likely factors quickly. Here, the candidate factors are x ± 1, x ± 2, x ± 4 . Let’s
try x = ±1 fist.

 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

The remainder is not zero which means x − 1 is not a factor of y .

[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

With x + 1 confirmed as a factor, we can see the factors have to be:

2
z = (x + 1)(x + 2)

z = (x+1)*(x+2)^2

z =

(x + 1)*(x + 2)^2

We would like to test our factorization by expanding.

expand(z)

ans =

x^3 + 5*x^2 + 8*x + 4

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

Finding the eigenvectors and the matrix P


rref([A + 1 * eye(3), zeros(3,1)])

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

rref([A + 2 * eye(3), zeros(3,1)])

ans =

1 7 2 0
0 0 0 0
0 0 0 0

v21 = [ -2 ; 0 ; 1];
v22 = [-7 ; 1 ; 0];

To test the vectors, we muliply.

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 = [v1, v21, v22]

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

We can also test with a conditional statement.

A == P * D * inv(P)

ans =

3x3 logical array

1 1 1
1 1 1
1 1 1

Thus, A is diagonalizable using the invertible matrix

−1 −2 −7
⎡ ⎤

P = ⎢ 0 0 1⎥
⎣ ⎦
1 1 0

and the diagonal matrix

−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

1.2 Row Operations Print to PDF

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]

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

Joining two objects is often called con


B=[A,v] programming languages.

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:

1. Swapping two rows


2. Multiplying a row by a non-zero scalar
3. Replacing any row with the sum of that row and a scalar multiple of another row

Strategic Goal: Row Echelon Form


We have two ways to solve a linear system, a partial row-reduction method with back-substitution, and a full row-
reduction method that leaves the solution on the right-hand side of the augmentation bar. The first step is to row-
redcue to ref form

Row Operation 1: Swapping Rows


In the augmented matrix B, we see that Row 2 has a pivot in the third position. Thus, we can make progress by
Examples of matrices in row-reduced form
swapping Row 1 and Row 2.

B([2 1],:)=B([1 2],:)

B =

2 0 -10 2
0 0 -2 -4
1 1 -3 3

 Tip

We can swap multiple rows at once.

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 2 3],:)=B([3 1 2],:)

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

Row Operation 2: Multiplying a Row by a Non-zero Scalar


Let’s return to matrix B. Multiplying through the first row by − 12 will turn the first pivot into a one:

b(2,:) = b(2,:) / (-2)

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(3,:) = b(3,:) / (-2)

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

This is the workhorse row op – learn it well, grasshopper.

We would now like to replace Row subtract Row 2 minus Row 1:

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

The bottom row means

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

which implies the row above it simplifies to

y + 2(2) = 2

so y = −2 . With these two values, we can solve for x:

x + 1(−2) − 3(2) = 3

x − 2 − 6 = 3

x = 11

We now know that

11
⎡ ⎤

x⃗ = ⎢ −2 ⎥
⎣ ⎦
2

is the solution vector.

Goal 2: Row-Reduce to RREF


First, let’s create a saved checkpoint, since all of our steps up to this point are correct.

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

And to get the zero in Row 1:

c(1,:)= c(1,:) + 3 * c(3,:)

c =

1 1 0 9
0 1 0 -2
0 0 1 2

We want the element a12 = 0 , so

c(1,:)= c(1,:) - c(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

We can verify that as required:

A*x
v

ans =

-4
2
3

v =

-4
2
3

We can also use a logical operator to check:

A*x == v

ans =

3x1 logical array

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

MATLAB does not have an REF function.

Hence, we have verified that we have the correct solution.

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

1.2.1 Lab 1 Print to PDF

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.

If your birthday is in:

January through April, do J.


May through August, do M.
September through December, do S.

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).

If your last name begins with:

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 ];

Part III: REF and solve


You must row-reduce one of the following matrices to REF and solve it. Each matrix below represents an
augmented matrix. The first three columns are the coefficient matrix A . The last column is a vector v ⃗. Your job is
to find the vector x⃗ such that

Ax ⃗ = v ⃗

If your first name begins with:

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

1.2.2 Homework Print to PDF

Row Reduce the Following Matrices


Do not use the rref command until you have finished row-reducing and solving. For quick reference, here are the
“by-hand” way to use the three elementary row operations in MATLAB. Practice both ways, in MATLAB and with
pencil and paper, as both will be essential tools in this course. For full solutions, you can copy the matrix into your
version of MATLAB and use the rref command. One version of the REF for each example is shown in the drop-
down solution area.

1. Swap rows 1 and 2 in matrix A .

a([1 2],:) = a([2 1],:)

2. Multiply row 2 by 7 in matrix A .

a(2,:) = 7 * a(2,:)

3. Replace row 2 with the sum of itself with 3 times row 1.

a(1,:) = a(2,:) + 3 * a(1,:)

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

1.3 Parameterized Solutions Print to PDF

Example 1

Basic and Free Variables


Consider the following example that might occur after row-reducing an augemented matrix:

−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

and x2 is a free variable, but the best we can do for x1 is:

−2x1 + 2x2 = 6

We solve for the basic variables in terms of any free variables.

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:

(x1 , x2 , x3 ) = (−3 + x2 , x2 , −2)

In the column-vector notation we have been using:

−3 + x2
⎡ ⎤

x⃗ = ⎢ x2 ⎥
⎣ ⎦
−2

or

−3 x2
⎡ ⎤ ⎡ ⎤

x⃗ = ⎢ 0 ⎥ + ⎢ x2 ⎥
⎣ ⎦ ⎣ ⎦
−2 0

which, after factoring out x2 , is equivalent to the vector equations

−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

The bottom row of the matrix

−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

where we see basic variables x1 , x3 , x5 and free variables x2 , x4 . Then x5 = 1 ,

x3 = 1 − 5x4

and

3x1 = 6 + 3x2 − 9x4

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.

This means our solutions will have the form:

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

which simplifies, after factoring, to

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

1.3.1 Lab 2 Print to PDF

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.

Part I: RREF with solutions in vector form


The augmented matrices in this section have already been row-reduced to REF. You must row-reduce all the way
to RREF and solve for all basic variables in terms of the free variables. When that is complete, write the
parameterized solutions in vector form.

If your birthday is in:

January through April, do J.


May through August, do M.
September through December, do S.

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 ] ;

Part II: REF, back-substitution and solutions in


paramteric form
The matrices below are augmented matrices that represent linear systems. Solve the linear system but row-
reducing to REF and back-substituting. You may also row-reduce to RREF, if you prefer. Write the solutions in
vector form.

If your first name begins with:

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 ] ;

Part III: Solve


Using either method, find the solutions to the linear systems represented by the augmented matrix below, and
write your solutions in vector form.

If your last name begins with:

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

Clearly, like addition, we are subtracting component-wise.

MATLAB and Vectors


Let’s create the vectors used in the above examples.

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

Addition and subtraction work exactly as you would guess.

v + u

ans =

7
4
0
4

v - u

ans =

-1
-6
4
14

Scalar multiplication also makes sense, for example, if r = 3 .

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.

Linear Combinations of Vectors


A linear combination of the vectors v 1⃗ , v 2⃗ , … v n⃗ uses scalars c 1 , c 2 , … c n as weights. If we have the vectors

5 0 3
⎡ ⎤ ⎡ ⎤ ⎡ ⎤

v⃗1 = ⎢ 3 ⎥ , v⃗2 = ⎢ 2 ⎥ , v⃗3 = ⎢ 4 ⎥


⎣ ⎦ ⎣ ⎦ ⎣ ⎦
−2 5 3

and weights c 1 = 4, c 2 = −1, c 3 = 2 , then the result is the linear combination:

5 0 3 26
⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤

⃗ + c2 v2
c1 v1 ⃗ + c3 v3
⃗ = 4⎢ 3 ⎥ − ⎢ 2 ⎥ + 2 ⎢ 4 ⎥ = ⎢ 18 ⎥
⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦
−2 5 3 −7

Linear Combinations in MATLAB


Let’s create the vectors from the above example.

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

Then we apply addition, subtraction and scalar multiplications as before.

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

2.2 Vector Equations and Spans

The span of a set of vectors


If the vector b ⃗ is in the span of the vectors {v 1⃗ , v 2⃗ , … v n⃗ }, then there is some linear combination that makes the
vector equation true.


⃗ + 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

We create the matrix A using the vectors as its columns.

A = [v1, v2, v3]

A =

5 0 3
3 2 4
-2 5 3

We want to augment A with the vector b ⃗ and then row-reduce.

[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 =

3x56 char array

' 1 0 0 68/13 '


' 0 1 0 90/13 '
' 0 0 1 -96/13 '

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

We create the vectors first, then row-reduce the augemented matrix.

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

2.3 Matrix Equations Print to PDF

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

The dot product is the sum of the component-wise products.

x⃗ ⋅ y ⃗ = (−1)(1) + (1)(3) + (5)(−1) = −3

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 = [ dot(r1,x) ; dot(r2,x) ; dot(r3,x) ]

b =

7
2
29

Of course, we can simply use MATLAB’s multiplication function to verify b ⃗ .

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 =

1.0000 0 0 -0.6486 -2.0000


0 1.0000 0 0.1486 1.0000
0 0 1.0000 0.0811 5.0000

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

2.4 Solution Sets Print to PDF

When we solve a linear system of the form


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

We solve the system and convert the solutions to vector form.

A=[ 5 2 -1 4 ;
5 -2 0 -2 ]

A =

5 2 -1 4
5 -2 0 -2

Let’s create an augmented matrix a for the homogeneous system.

 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.

The zeros function in MATLAB unsuprising


a = [A, zeros(2,1)]
matrix of zeros of the given dimnesions, as

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 .

5x1 + 2x2 = x3 − 4x4



−4x2 = −x3 + 6x4

5x1 + 2x2 = x3 − 4x4

1 3 ⟹
x2 = x3 − x4
4 2

We substitute for x2 in the first equation and simplify.

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

This means that any linear combination of the vectors

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 =

1.0000 0 0 1.3333 1.3333 3.3333


0 1.0000 0 1.5333 1.3333 3.1333
0 0 1.0000 -1.9556 -0.5556 -2.8222

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

Part I. Determine if a vector is in the span of a set of


vectors
If your birthday is in:

January through April, do the sets of vectors v ⃗.


May through August, do the sets of vectors x⃗.
September through December, do the sets of vectors y ⃗.

Determine if the vector


 Note

1 If the columns of matrix A are the vecto


⎡ ⎤
{a1 ⃗ , a2 ⃗ } , then
⃗ , … , ak
⎢ 4⎥
v⃗ = ⎢ ⎥
⎢ 1⎥ ⃗ , a2
A = [a1 ⃗ , … , ak
⃗ ]

⎣ ⎦
7

is in the Span{v 1⃗ , v 2⃗ , v 3⃗ } where


The same basic notation works in MATLAB to
vectors a1, a2 and a3.

0 3 1
⎡ ⎤ ⎡ ⎤ ⎡ ⎤

⎢ 0⎥ ⎢ 6⎥ ⎢ 1⎥
A = [a1, a2, a3]

v1 = ⎢ ⃗ = ⎢
⎥ , v2 ⃗ = ⎢
⎥ , v3 ⎥
⎢ −1 ⎥ ⎢ 0⎥ ⎢ 1⎥

⎣ ⎦ ⎣ ⎦ ⎣ ⎦
0 12 2

Determine if the vector

−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 ] ;

Determine if the vector

2
⎡ ⎤

⎢ −3 ⎥
y⃗ = ⎢ ⎥
⎢ −1 ⎥

⎣ ⎦
−1

is in the Span{y 1⃗ , y 2⃗ , y 3⃗ } where

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 ] ;

Part II. Matrix-vector multiplication


Use the dot product function dot to show matrix-vector multiplication.

 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,:)

If your first name begins with:


 Tip
A through D, do A.
The MATLAB function dot works equal
D through J, do D. row vectors and column vectors.
J through Z, do J.

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 ] ;

Multiply Dx⃗ where

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

Part III: Solve the homogeneous system of equations


Solve the homogenenous system of equations which are of the form Av ⃗ = 0

, but use row operations instead of the rref
function. Write the solution set in vector form.

If your last name begins with:

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

B = [7 18 39 -16 -1 ;0 -1 -1 2 0 ;-9 -22 -49 18 1 ] ;


z = zeros(3,1) ;
[B,z]

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]

ans = Print to PDF

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

2.5 Linear Independence Print to PDF

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

Examples: Linearly indepedent


Determine if the set of vectors {x1 , x2 , … , x3 } and {y 1 , y 2 , … , y 3 } are linearly independent.

−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.

We’ll do the same for a matrix Y .

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.

Linear Dependence Relation


Let’s look at the example with the vectors y i⃗ and the matrix Y . Instead of thinking of it as three vectors, let’s
consider what it would reprensent as an augmented matrix.

⎡ 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

using the weights − 3 , 1 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 =

3x1 logical array

1
1
1

The 1’s indicate true for every value.

The linear combination of

1 4 1
⎡ ⎤ ⎡ ⎤ ⎡ ⎤
1 1
−( )⎢ 5⎥ + ( ) ⎢ 2 ⎥ = ⎢ −1 ⎥
3 3
⎣ ⎦ ⎣ ⎦ ⎣ ⎦
5 5 0

is called the linear dependence relation.

Spans and Linear Dependence


If a vector b ⃗ is in the Span{v 1⃗ , v 2⃗ , … , v k⃗ }, the set of vectors


⃗ , 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.

Finding the null space

Example 1. Find the null space of the matrix A.

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

So the solution set is of the form:

⎡ 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.

for i = 1:10 k = randi([-50 100],1,1); A * k * x end

Example 2. Find the null space of the matrix B.

−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

Again, we need the matrix C.

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

Then, the column space of A is the span of the vectors v 1 , v 2 .

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

Part I. Linear Independence


Determine if the sets of vectors are linearly independent or linearly dependent. Explain your reasoning for each
set. If they are linearly dependent, give the dependence relation.

If your birthday is in:

January through April, do the sets of vectors v ⃗.


May through August, do the sets of vectors x⃗.
September through December, do the sets of vectors y ⃗.

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 ] ;

Part II. Null Space in Vector Form


Find the null space for the given matrix, and write the solution set in vector form.

If your first name begins with:


 Note
A through D, do A.
The null space of a matrix A is the set
D through J, do D.
vectors x⃗ such that Ax⃗ = 0⃗ .
J through Z, do J.

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 ] ;

Part III: Column Space


The column space of matrix A is the span of its columns. Find the column space for the following matrices.

If your last name begins with:

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

2.7 Basis and Dimension


We are in a great position to understand what it means to be a basis and the dimension of subspace because we
have been writing solutions to systems of equations in vector form since chpater 1. We repeat this essential
definition directly from the Margalit text.

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

Example 1: The basis for a set of vectors.


Given the following set of vectors, find a basis for the Span{v 1⃗ , v 2⃗ , v 3⃗ } .

−1 −6 −4
⎡ ⎤ ⎡ ⎤ ⎡ ⎤
⃗ = ⎢ −4 ⎥ , v 2
v1 ⃗ = ⎢ −20 ⎥ , v 3
⃗ = ⎢ −13 ⎥

⎣ ⎦ ⎣ ⎦ ⎣ ⎦
1 6 4

Let’s gather the column vectors into a matrix M for convenience.

M = [-1 -6 -4 ; -4 -20 -13 ; 1 6 4 ];


v1 = M(:,1)
v2 = M(:,2)
v3 = M(:,3)

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.

Example 2: Another basis for a set of vectors.


Given the following set of vectors shown as columns of the matrix R, find a basis for the
⃗ , v2
Span{v 1 ⃗ , v3
⃗ , v4
⃗ , v5
⃗ } .

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 =

1.0000 0 -0.2500 0.5000 0


0 1.0000 0.5000 1.0000 0
0 0 0 0 1.0000
0 0 0 0 0

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

The Column Space


Column Space of A
The Span{a1⃗ , a2⃗ , ⋯ , an⃗ } where the vectors ai⃗ are the columns of A .

So the column space for matrix R from Example 2 has the same basis as the span of the vectors.

Basis for Null Space of A


We have already shown this in section 2.6. We solve the homogeneous system Ax0
⃗ ⃗, and write the solution set in

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

2.8 Bases as Coordinate Systems Print to PDF

The standard basis vectors are the columns of the n × n identity matrices which are generally referred to as In .

Identity matrix and standard basis for R :


2

I2 = eye(2)

I2 =

1 0
0 1

We refer to the standard basis vectors as e 1⃗ and e 2⃗ .

e1 = I2(:,1)

e1 =

1
0

e2 = I2(:,2)

e2 =

0
1

Identity matrix and standard basis for R


3

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.

Example: Alternate basis for R


3

Suppose that we have the following vectors:

−1 1 −1 −3
⎡ ⎤ ⎡ ⎤ ⎡ ⎤ ⎡ ⎤
⃗ = ⎢
v1 1 ⎥ , v2
⃗ = ⎢ 9 ⎥ , v3
⃗ = ⎢ −1 ⎥ and w⃗ = ⎢ 5⎥
⎣ ⎦ ⎣ ⎦ ⎣ ⎦ ⎣ ⎦
0 5 −2 2

Verifying {v1⃗ , v2⃗ , v3⃗ } is a basis for R3


Let’s create a matrix whose columns are the candidates for the basis vectors, then row-reduce.

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.

Finding the B -coordinates of a point


We want to determine how to write the vector w⃗ as a linear combination of the basis vectors. The coordinates
c1 , c2 , c3 will be the coefficients of the linear dependence relation when we solve the vector equations

⃗ + c2 v2
c1 v1 ⃗ + c3 v3
⃗ = w⃗

which is equivalent to the matrix equations

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

We augment the matrix and row reduce [B, w⃗ ].

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

We can verify using the columns of matrix B.

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

2.9 The Rank Theorem Print to PDF

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

Example: Rank of Matrix


M = [-4 3 25 11 ; -12 7 81 35 ; -2 2 11 5 ]
rref(M)

M =

-4 3 25 11
-12 7 81 35
-2 2 11 5

ans =

1.0000 0 -8.5000 -3.5000


0 1.0000 -3.0000 -1.0000
0 0 0 0

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

2.9.1 Lab 5 Print to PDF

Part I. Find a basis for the span of the set of


vectors
For the set of vectors indicated, find a basis for their span.

If your birthday is in:

January through April, do the sets of vectors v ⃗.


May through August, do the sets of vectors x⃗.
September through December, do the sets of vectors y ⃗.

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 ];

Part II. Find a basis for the column space of the


matrix
For the matrix indicated, find a basis for the column space.

If your first name begins with:

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 ];

Part III: Find the B-coordinates of the vector


Write the vector

8
w⃗ = [ ]
−2

in B -coordinates where the basis vectors b 1⃗ , b 2⃗ are given.

If your last name begins with:

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

3.1 Matrix Transformations

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.

Consider an arbitrary vector in R2 .

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

Let’s create the augmented matrix and find the preimage.

y = [-2 ; 1]
rref([A,y])

y =
Print to PDF
-2
1

ans =

1.0000 -0.5000 0 1.0000 -3.5000


0 0 1.0000 1.0000 -3.0000

Because the linear system is consistent, we know that y ⃗ is in the range of T ⃗


(x ) . We will dig deeper into these
concepts in the next section.

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

3.2 One-to-one and Onto Transformations

Domain and Codomain


A transformation

⃗ = 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.

Theorem. One-to-one matrix transformations.


Let A be an m × n matrix, and let T ⃗ = Ax ⃗
(x ) be the associated matrix transformation. The following
statements are equivalent:

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.

Theorem. Onto matrix transformations.


Let A be an m × n matrix, and let T ⃗ = Ax ⃗
(x ) be the associated matrix transformation. The following
statements are equivalent:

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

4. The columns of A span Rm .


5. A has a pivot in every row.
6. The range of T has dimension m.

Let’s consider the same 4 matrices as before.

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 =

1.0000 0.5000 0 0 -1.2500


0 0 1.0000 0 1.0000
0 0 0 1.0000 -1.0000
Print to PDF

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

3.3 Linear Transformations

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

Finding the standard matrix for a linear


transformation
The Margalit text is excellent, and you should spend a goodly amount of time with the visualization of linear
transformations there.

 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 ⃗

for some m × n matrix A , then

⃗ ), T (e 2
A = [T (e 1 ⃗ ), ⋯ , T (e m
⃗ )]

where e i⃗ are the standard basis vectors in Rn .

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

Reflect across x-axis.


Reflecting across the x-axis will not affect vectors on the x-axis, so

1 1
⃗ ) = T ([
T (e 1 ]) = [ ]
0 0

but

0 0
⃗ ) = T ([
T (e 2 ]) = [ ]
1 −1

The standard matrix is

1 0
A = [ ]
0 −1

where the columns of A are the vectors T (e 1⃗ ) and T (e 2⃗ ).

Reflect across y-axis.


Reflecting across the y -axis will not affect vectors on the y -axis, so

0 0
⃗ ) = T ([
T (e 2 ]) = [ ]
1 1

but

1 −1
⃗ ) = T ([
T (e 1 ]) = [ ]
0 0

The standard matrix is

−1 0
A = [ ]
0 1

where the columns of A are the vectors T (e 1⃗ ) and T (e 2⃗ ).

Reflection through the origin


A reflection through the origin is a reflection through both the x and y -axis. We can compose the two functions
which means multiplying the standard matrices in the proper order.Suppose that the linear transformation T1 is
the reflection through the x-axis and that T2 is the reflection through the y -axis. Then

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 ⃗

and the standard matrix for a reflection through the origin is

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

but e 1⃗ is not affected

k 0
A = [ ]
0 1

is the standard matrix associated with horizontal scaling.

Vertical scaling
The same reasoning applies, and

1 0
A = [ ]
0 k

is the standard matrix associated with vecrtical scaling.

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.

Solution. Find each standard matrix, then compose them.

1. Stretch vertically by a factor of 4.

1 0
A1 = [ ]
0 4

2. Rotate by 270∘ . We can have MATLAB calculate the matrix for us

R = [ cosd(270) -sind(270) ; sind(270) cosd(270) ]

https://straightdraw.github.io/Linear/ch3/3.html 3/4
3/4/24, 8:39 PM 3.3 Linear Transformations — Linear Algebra with MATLAB

which produces the correct standard matrix  Note

The MATLAB functions sin and cos re


0 1
A2 = R = [ ] radians. To use degrees instead, MATL
−1 0 the functions sind and cosd.

3. Reflect across x-axis.

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

3.4 Matrix Multiplication Print to PDF

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 .

Suppose we wish to multiply matrices A and B.

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

Note that we multiplied a 3 × 4 matrix A by a 4 × 3 matrix B. Solely in terms of dimension,

(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

The entry c 11 = 6 is the dot product of Row 1 of A and Column 1 of B.

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 =

The entry c 12 = 15 is the dot product of Row 2 of A and Column 1 of B.

dot(A(2,:),B(:,1))

ans =

15

The entry c 23 = 17 is the dot product of Row 2 of A and Column 3 of B.

dot(A(2,:),B(:,3))

ans =

17

Problems with matrix multiplication


Matrices are not real numbers, so while we can multiply them, we should not expect them to behave “normally.”
There are three problems described in the Margalit text which you should review carefully.

1. Matrix multiplication is not commutative even when it is possible to multiply the matrices.

AB is not usually equal to BA

2. Cancellation does not necessarily work, even when AB = 0 .

AB = AC ⇏ B = C

3. It is possible, even if A ≠ 0 and B ≠ 0 , for

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 ] ;

To calcuate the Row 1 Column 1 entry of C , we have c 11 = a11 + b 11 = 1 .

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 =

To calcuate the Row 2 Column 2 entry of C , we have c 22 = a22 + b 22 = 3 .

A(2,2) + B(2,2)

ans =

To calcuate the Row 3 Column 1 entry of C , we have c 31 = a31 + b 31 = 8 .

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

Part I. One-to-one Transformation


The given matrix is the standard matrix of a linear transformation. Determine if the linear transformation is one-
to-one.

If your birthday is in:

January through April, do matrix J .


May through August, do matrix M .
September through December, do matrix S .

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 ] ;

Part II. Matrix Multiplication


Using MATLAB’s dot function and not the multiplication operation, calculate the products of the following
matrices.

If your first name begins with:

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 ];

Part III: Inverse Matrix


Use row reduction (showing all steps) to find the inverse matrix.

If your last name begins with:

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

B = [6 -8 -5;6 -7 -3;3 -4 -2] ;

−3 −3 13 Print to PDF
⎡ ⎤

H = ⎢ −1 −2 3⎥
⎣ ⎦
1 2 −5

H = [-3 -3 13 ; -1 -2 3;1 2 -5] ;

1 0 −8
⎡ ⎤

R = ⎢ −2 0 19 ⎥
⎣ ⎦
−2 −2 11

R = [1 0 -8;-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

3.6 Invertible Matrix Theorem


Invertible Matrix Theorem (IMT). Let A be an n × n matrix, and let T : R
n
→ R
n
be the matrix transformation
⃗ = Ax ⃗
T (x ) . The following statements are equivalent:

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.

Using the IMT


We use the IMT all the time. Is a set of vectors a basis for Rn ? Combine them into a matrix and check to see if the
matrix is invertible. Is the linear transformation one-to-one? Verify the null space contains only the 0⃗. Does A
have an inverse? Row reduce and check how many pivots the matrix has.

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

We create the matrix B ⃗ ⃗ ⃗ ⃗ ⃗


= [b 1 , b 2 , b 3 , b 4 , b 5 ] and row reduce.

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 =

1.0000 -4.0000 0.0000 2.0000 -2.0000


-25.0000 110.0000 -7.0000 -61.0000 66.0000
10.0000 -45.0000 3.0000 25.0000 -27.0000
12.0000 -52.0000 3.0000 29.0000 -31.0000
23.0000 -101.0000 7.0000 56.0000 -61.0000

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

5.1 Eigenvalues and Eigenvectors


Eigenvector
An eigenvector of A is a nonzero vector v ⃗ in Rn such that Av ⃗ = λv ⃗ , for some scalar λ.
Eigenvalue
An eigenvalue of A is a scalar λ such that the equation Av ⃗ = λv ⃗ has a nontrivial solution.

Terminology. If Av ⃗ = λv ⃗ for some vector v ⃗ ≠ 0



, we say that λ is the eigenvalue for v ⃗, and that v ⃗ is an
eigenvector for λ.

Determining if a vector is an eigenvector of a


matrix
Print to PDF

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

By inspection, we see that Av ⃗ is not a scalar multiple of v ⃗, so v ⃗ is not an eigenvector of A .

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

Solution. Same question as above, so we multiply and check.

B = [-4 16 -14 22 ; -6 20 -12 24 ; 3 -8 9 -11 ; 4 -12 8 -14 ];


y = [1 ; -1 ; 0 ; 1 ]

y =

1
-1
0
1

B*y

ans =

2
-2
0
2

Clearly, By ⃗ = 2y ⃗ , so 2 is an eignevalue of matrix B, and y is its associated eigenvector.

Finding eignevalues
The eignevalues of a matrix A are possible values λ such that

Av ⃗ = λ v ⃗

which, after some algebra, is equivalent to solving a homogeneous set of equations.

Av ⃗ = λv ⃗


⟺ Av ⃗ − λ v ⃗ = 0


⟺ Av ⃗ − λI v ⃗ = 0


⟺ (A − λI )v ⃗ = 0

This means we can test eigenvalues by creating the matrix

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

To see if the null space is empty, we row-reduce the augmented matrix.

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

We are testing the specific equality:

A * v == 3 * v

ans =

3x1 logical array

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

5.2 The Characteristic Polynomial


Characteristic Polynomial
For an n × n matrix A , the characteristic polynomial of A is

p(λ) = det (A − λI )

Section 1

Finding eignevalues
The eignevalues of a matrix A are possible values λ such that

Av ⃗ = λ v ⃗

which, after some algebra, is equivalent to solving a homogeneous set of equations.

Av ⃗ = λv ⃗


⟺ Av ⃗ − λ v ⃗ = 0


⟺ Av ⃗ − λI v ⃗ = 0


⟺ (A − λI )v ⃗ = 0

Example: Eigenvalues and Eigenvectors


Find the eigenvalues and associated eigenvectors of matrix A .

3 0 0
⎡ ⎤

A = ⎢ 2 15 −14 ⎥
⎣ ⎦
2 12 −11

Example 1a: Find the characteristic polynomial of matrix A


The first step in finding the eigenvalues of matrix A is determining its characteric polynomial which means finding
the determinant of A − λI .

3 0 0 1 0 0
⎛⎡ ⎤ ⎡ ⎤⎞

det (A − λI ) = det ⎜⎢ 2 15 −14 ⎥ − λ ⎢ 0 1 0 ⎥⎟


⎝⎣ ⎦ ⎣ ⎦⎠
2 12 −11 0 0 1

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

we know the characteristic polynomial is the product

2
p(λ) = (3 − λ)(λ − 4λ + 3)

3 2 2
= −λ + 4λ − 3λ + 3λ − 12λ + 9
3 2
= −λ + 7λ − 15λ + 9

We can confirm using the MATLAB charpoly function.

A = [3 0 0 ; 2 15 -14 ; 2 12 -11 ];
charpoly(A)

ans =

1 -7 15 -9

Example 1b: Finding the eigenvalues


The coefficients from the charpoly function match our work if we mulitply through the expression by −1 which
will be mathematically correct since the eigenvalues of the matrix are the roots of the characteristic polynomial. In
fact, it was a waste of time algebraically to write p(λ) in expanded form since we actually need to set it equal to
zero and factor it.

2
p(λ) = (3 − λ)(λ − 4λ + 3)

= −(λ − 3)(λ − 3)(λ − 1)

2
= −(λ − 3) (λ − 1)

We set the characteristic polynomial equal to zero and solve.

2
−(λ − 3) (λ − 1) = 0

We have two eigenvalues.

λ = 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.

Example 1c: Finding the eigenvectors for λ = 1

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

We actually want to row reduce the augmented matrix [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

We can see that x3 is a free variable and that

x1 = 0

x2 = x3

So v ⃗ is an eigenvector.

0
⎡ ⎤

v⃗ = ⎢ 1 ⎥
⎣ ⎦
1

We can test by multiplying the matrix by the eigenvector.

v = [0 ; 1 ; 1 ];
A*v

ans =

0
1
1

We can also execute a code block with a conditional to check. Since

A*V == 1*v

evaluates True, we know that λ = 1 is eigenvalue of A .

Example 1d: Finding the eigenvectors for λ = 3

Substituting λ = 3 into A − λI = 0

A − 3I = 0

We actually want to row reduce the augmented matrix [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

A solution vector v ⃗ has the form

−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 =

3x1 logical array

1
1
1

For clarity, it helps to see the multiplication steps.

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 .

Example 2: Find eigenvalues and eigenvectors with


MATLAB
Find all the eigenvalues and eigenvectors for matrix B.

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.

B = [-14 -78 26 66 ; -2 -12 10 10 ; 6 27 -4 -24 ; -9 -48 21 41 ];


charpoly(B)

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 =

x^4 - 11*x^3 + 38*x^2 - 40*x

Using polynomialReduce function to determine fully factored


form of characteristic polynomial
The function polynomialReduce returns the remainder when one polynomial is divided by another.

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 =

x^3 - 11*x^2 + 38*x - 40

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

To experiment, let’s see if the factor x + 5 dvides q(x) evenly.

[r, q2] = polynomialReduce(q, x+5)

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 =

x^2 - 16*x + 118

With a remainder of −630, we know that x + 5 is cleary not a factor. Let’s retry it with x − 5 .

[r, q2] = polynomialReduce(q, x-5)

r =

q2 =

x^2 - 6*x + 8

[r,q3] = polynomialReduce(q2, x-4)

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 =

x*(x - 2)*(x - 4)*(x - 5)

expand(z)

ans =

x^4 - 11*x^3 + 38*x^2 - 40*x

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

Finding eigenvalues for each eigenvalue

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

With x4 free and x3 = 0 , solve to find eigenvector.

1
⎡ ⎤

⎢ 2/3 ⎥

v0 = ⎢ ⎥
⎢ 0⎥
⎣ ⎦
1

We are allowed to clear the denominators in the vector.

3
⎡ ⎤

⎢ 2⎥
⃗ = ⎢
v0 ⎥
⎢ 0⎥

⎣ ⎦
3

We will verify all of the eigenvectors at the end.

For λ = 2

rref([B - 2 * eye(4), zeros(4,1)])

ans =

1 0 0 4 0
0 1 0 -2 0
0 0 1 -1 0
0 0 0 0 0

With x4 free, solve to find eigenvector.

−4
⎡ ⎤

⎢ 2⎥
⃗ = ⎢
v2 ⎥
⎢ 1⎥
⎣ ⎦
1

For λ = 4

rref([B - 4 * eye(4), zeros(4,1)])

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

With x4 free, solve to find eigenvector and clear denominator.

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

rref([B - 5 * eye(4), zeros(4,1)])

ans =

1 0 0 2 0
0 1 0 -2 0
0 0 1 -2 0
0 0 0 0 0

With x4 free, solve to find eigenvector.

−2
⎡ ⎤

⎢ 2⎥
⃗ = ⎢
v5 ⎥
⎢ 2⎥
⎣ ⎦
1

We can now multiply the matrix B by each eigenvector to verify the

B v ⃗ = λv ⃗

property holds for each of them.

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

Thus, we have verified all the eigenvalues and associated eigenvectors.

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

5.3 Similarity Print to PDF

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

5.4 Diagonalization Print to PDF

The diagonalization of a matrix A , provided it exists, can be written as

$$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

Finding the eigenvalues and matrix D


As we found in section 5.2, the characteristic polynomial is found by calculating the determinant of the matrix
A − λI .

A = [-3 -7 -2 ; 0 -2 0 ; 1 7 0 ];
syms x
y = charpoly(A,x)

y =

x^3 + 5*x^2 + 8*x + 4

Testing factors for zero remainder using polynomialReduce function


MATLAB’s polynomialReduce function divides one polynomial by another of lesser degree returning the
remainder. This allows us to test likely factors quickly. Here, the candidate factors are x ± 1, x ± 2, x ± 4 . Let’s
try x = ±1 fist.

 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

The remainder is not zero which means x − 1 is not a factor of y .

[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

With x + 1 confirmed as a factor, we can see the factors have to be:

2
z = (x + 1)(x + 2)

z = (x+1)*(x+2)^2

z =

(x + 1)*(x + 2)^2

We would like to test our factorization by expanding.

expand(z)

ans =

x^3 + 5*x^2 + 8*x + 4

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

Finding the eigenvectors and the matrix P


rref([A + 1 * eye(3), zeros(3,1)])

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

rref([A + 2 * eye(3), zeros(3,1)])

ans =

1 7 2 0
0 0 0 0
0 0 0 0

v21 = [ -2 ; 0 ; 1];
v22 = [-7 ; 1 ; 0];

To test the vectors, we muliply.

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 = [v1, v21, v22]

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

We can also test with a conditional statement.

A == P * D * inv(P)

ans =

3x3 logical array

1 1 1
1 1 1
1 1 1

Thus, A is diagonalizable using the invertible matrix

−1 −2 −7
⎡ ⎤

P = ⎢ 0 0 1⎥
⎣ ⎦
1 1 0

and the diagonal matrix

−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

You might also like