Linear Algebra Lab Packet 2020
Linear Algebra Lab Packet 2020
1
.
2
Contents
1 Lab 1: Introduction to Computer Graphics and Matrix Algebra 7
1.1 Connection to Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
1.2 Introduction to Octave . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.3 Matrices Algebra . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.4 Addition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.5 Multiplication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
1.6 Bonus Application: Convex Combinations . . . . . . . . . . . . . . . . . . . 13
3
7 Lab 7 - Applications of Markov Chains and Singular Value Decomposition 77
7.1 Pre-Lab Reading: Applications of SVD . . . . . . . . . . . . . . . . . . . . . 77
7.2 Example 1: Image Compression . . . . . . . . . . . . . . . . . . . . . . . . . 78
7.3 Example 2: Approximating Matrix Rank . . . . . . . . . . . . . . . . . . . . 79
7.4 Example 3: Noise Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
7.5 Markov Chain Application: Board Games . . . . . . . . . . . . . . . . . . . 81
Pre-Lab Assignments
• Lab 1: No pre-lab assignment.
• Lab 3: Read and answer the questions from Section 3.1 (through Colley Method -stop
at 3.2). Turn in pre-lab questions with Lab 3 report.
• Lab 5: Watch the video https://youtu.be/ysOEnGg_rz0 and then answer the follow-
ing questions from Section 5.1.
• Lab 6: Read through Common Misconceptions and answer the first 5 pre-lab questions
before class.
4
• Extra Lab 9: Read and answer questions from Section 9.1.
References
[1] W Colley. Colley’s bias free college football ranking method, 2002.
[2] Amy N Langville and Carl D Meyer. Who’s# 1?: the science of rating and ranking.
Princeton University Press, 2012.
and Tomography Labs and Diffusion Labs are from the ImageMath.org project created by
Dr. Tom Asaki, Dr. Heather Moon, and Dr. Marie Snipe. This material is based upon work
supported by the National Science Foundation under grants DUE-1503929, DUE-1642095,
DUE-1503870, and DUE-1503856. Any opinions, findings, and conclusions or recommenda-
tions expressed in this material are those of the author(s) and do not necessarily reflect the
views of the National Science Foundation.
5
Copy of Consent Form: Below is a copy of the consent form from our study of our Labs
from this course:
I agree to participate in the study entitled, “The Impact of the Use of Application-focused
Labs in Linear Algebra” being conducted by Mr. Michael Smith and Dr. Amanda Harsy,
mathematics professors conducting research through Lewis. I have been informed that the
purpose of the study is to research the impact and usefulness of incorporating labs in linear
algebra courses. The data gathered through these surveys will also be used as feedback to
improve the labs for our Linear Algebra students.
I understand that if I agree to participate in this study, I will be asked to complete a total
of seven 10-15 minute surveys administered after each lab.
I understand that all information gathered during this study will be kept confidential by the
researchers. The professors disseminating the data will be given no identifying information,
so my answers to the prompts will be anonymous. No names are needed and for the research
and no identifying information will be shared. Data collected will be kept on a password-
protected computer for three years and then deleted.
I realize that Lewis University does not provide compensation for, nor do the institutions
carry insurance to cover injury or illness incurred as a result of participation in this research
project.
I understand that my consent to participate in this project does not constitute a waiver of
any legal rights or redress I might have as a result of my participation, and I acknowledge
that I have received a copy of this consent form.
I am aware that my participation is voluntary and I may withdraw at any time without
penalty or prejudice. My decision whether or not to participate will not jeopardize my future
relations with Lewis University and will not jeopardize my success in my current and future
mathematics courses. I understand that I may refuse to answer any question that I do not
wish to answer. If I have any additional questions concerning this study, I may contact Mr.
Michael Smith at [email protected] or Dr. Amanda Harsy at [email protected]. I
understand that if I wish further information regarding my rights as a research subject, I may
contact the Lewis University Institutional Review Board Administrator, Dr. William Chura,
Associate Provost for Research and Faculty Development, [email protected], 815-836-597.
This study has been approved by the Institutional Review Board at Lewis University.
6
1 Lab 1: Introduction to Computer Graphics and Ma-
trix Algebra
“Did you know that the first Matrix was designed to be a perfect human world? ” -Agent Smith, The Matrix
Examples:
1
2 7 9 2 7 9 1 5 20
A= = , B= , C=
3 , D= 2 4 6 .
0 1 5 0 1 5 4 1
0
1. What are the dimensions of the matrices above?
Each element corresponds to a grayscale pixel. Grayscale values vary from 0 (black) to 255
(white). The image represented by matrix A’s upper lefthand corner pixel has a grayscale
7
We can lighten her eyes by multiplying the matrix of pixels for the Mona Lisa by 1.4.
We can also invert images. If we want a white pixel (255) to become black (0), and black
(0) to become white. We want to the points (255,0), (0,255) which correspond to the line
y = −x + 255. We can turn this into a matrix equation. If we let M be the matrix of
the Mona Lisa and B be the matrix which has every entry as 255, then our new matrix
8
3. Experiment with the Command Window: Type 1+1 and hit enter. Type 10*7*11.
2 7 9
You can create the matrix A = by typing [2 7 9; 0 1 5]. You can define
0 1 5
the matrix
by typing A = [2 7 9; 0 1 5]. What is the syntax for defining a matrix
1 5
B= ?
4 1
4. We are now going to experiment with inverting pictures. Go to Blackboard and down-
load the Lab 1 matlab file. Use the picture provided or add your own picture. (If using
your own picture, you will need to rename the image in the octave code and may need
to resize your picture -make it smaller. Resizing a picture can be done several ways
-one easy way is to open your photo up in paint and resize it there.).
a) Change the numbers for the following
b) Save or snip a picture of the inverted image you made! Post your “inverted photo”
in the Blackboard discussion board for Applied Linear Algebra under the discussion
Lab 1. Y
Note One issue you may have with the code is the following: If your browser is opening the
jpg and mfile for the Inversion problem in another tab, you can right click on the file (before
you download it form Bb) and click on Save Link as. Use this to save it to your computer
and then you can drag it to the Octave online or use the Upload button to the right under
”file” which you can upload the mfile AND the jpg.
9
1.3 Matrices Algebra
1.4 Addition
In this course, we will be using matrices a lot and like many other mathematical objects,
we like to be able to combine them. The first way we ever learned to combine numbers was
using
addition.
Matrix addition
is so easy it could almost become
anafterthought1 :
1 2 3 0 4 8 1+0 2+4 3+8 1 6 11
+ = =
6 −1 4 −5 1 2 6 + (−5) −1 + 1 4 + 2 1 0 6
1 2 3 0 4 8 1−0 2−4 3−8 1 −2 −5
− = =
6 −1 4 −5 1 2 6 − (−5) −1 − 1 4 − 2 11 −2 2
1.5 Multiplication
Being able to add matrices encourages us to consider multiplication of matrices. Please
watch my echopen lecture on Matrix Multiplication which is located in the echopen lecture Bb
folder.If you are still having trouble understanding Matrix Multiplication, watch these videos:
https://www.youtube.com/watch?v=aKhhYguY0DQ and https://www.youtube.com/watch?
v=OAh573i_qn8
1
If you still want some guide with this, watch the Kahn Academy Video on Adding and Subtracting
Matrices: https://www.youtube.com/watch?v=WR9qCSXJlyY
10
6. Compute the following sums of matrices. If the addition is not defined, state how you know.
1 1 0
1 −1 2
1 1 1 0
1 2 0
(a) P + Q = 2 1 3 −1 + =
3 0 0
2 2 0 0
2 2 2
1 0 −1
0 2 3 4 1 1 1 0
(b) R + P = 1 −1 −3 −1 + 2 1 3 −1 =
−1 −2 0 1 2 2 0 0
1 1 1 0 0 2 3 4
(c) P + R = 2 1 3 −1 + 1 −1 −3 −1 =
2 2 0 0 −1 −2 0 1
1 1 0
1 −1 2
0 0 −1 0 2 1
1 2
0
(d) Q + S = 3 + −3 −1 −2 1 2 0 =
0 0
2 2 −1 0 1 2 −1
2 2
1 0 −1
(e) What must be true about matrices in order to add them?
7. Compute 3P and 2Q. If the scalar product is not defined, state how you know.
1 1 1 0
(a) 3P = 3 · 2 1 3 −1 =
2 2 0 0
1 1 0
1 −1 2
1 2 0
(b) 2Q = 2 · =
3 0 0
2 2 2
1 0 −1
(c) Will scalar multiplication ever not be defined for a given m × n matrix?
11
−2 −2 1
4 −4 5 1 −1 0
8. Let A = , B = 3 −5, C = , D = 2 . Compute the
4 −4 −3 2 0 −3
−4 5 −3
following matrix products. If the matrix product is not defined, state how you know.
−2 −2
4 −4 5
(a) A · B = · 3 −5 =
4 −4 −3
−4 5
−2 −2
4 −4 5
(b) B · A = 3 −5 · =
4 −4 −3
−4 5
4 −4 5 1 −1 0
(c) A · C = · =
4 −4 −3 2 0 −3
1
4 −4 5
(d) D · A = 2 · =
4 −4 −3
−3
1
4 −4 5
(e) A · D = · 2 =
4 −4 −3
−3
−2 −2
4 −4 5 1 −1 0
(f) A · B · C = · 3 −5 · =
4 −4 −3 2 0 −3
−4 5
Hint: use a previous answer.
9. If you are willing to provide feedback for this lab, please fill out the survey for our study at
the following link: http://bit.ly/linearalgebralabs2020
12
1.6 Bonus Application: Convex Combinations
Now that we know about vectors and how images can be represented by vectors, we would like to
show a neat application of vectors in computer graphics. The following questions are bonus and are
not required for this first lab. First listen to the echopen lecture on Convex Combinations posted
in the Lab 1 section of Blackboard. Then look at the slides posted in the same section in Bb.
These are slides we have truncated from freely shared materials from Coding the Matrix ’s website:
http://codingthematrix.com/ and Tim Chatier’s (The author of When Life is Linear ) Website
http://academics.davidson.edu/math/chartier/ . We are using their slides because they have
nice visualizations of these applications.
6 −4
6. Calculate the convex combination of a +b
−2 8
Remember b = 1 − a for convex combinations.
(a) for a = 0
(c) for a = .5
(d) for a = 1
7. What two applications of convex combinations did the slides demonstrate? Can you think of
any other possible uses for convex combinations?
13
14
2 Lab 2: Radiography and Tomography Part 1
2.1 Pre- Lab 2 (Rad/Tom Lab Part 1 Introduction)
Definition 2.1. An image is a finite ordered list of real values with an associated geometric
array description.
Examples:
4
1 8
1 4 7 1 ... 10
5
2 5 ... 2 ... 2 9
6
3 6 3 3 8
7
4 5 6 7
Definition 2.2. The sum of two images is the image that results by adding corresponding
values of the ordered list.
Definition 2.3. The sum of two images is the image that results by pixel-wise addition.
Definition 2.4. Given two images x and y with (ordered) intensity values (x1 , x2 , ..., xn )
and (y1 , y2 , ..., yn ), respectively, the sum, written z = x + y is the image with intensity values
zi = xi + yi for all i ∈ {1, 2, ..., n}.
Scalar Multiplication: We can multiply an image by a scalar (number) to get a new image!
Definition 2.5. A scalar times an image is the image which results from multiplication
of each of the intensity values (or values in the ordered list) by that scalar.
Definition 2.6. A scalar times an image is the image that results by pixel-wise scalar mul-
tiplication.
Definition 2.7. Given scalar a and image x with (ordered) intensity values (x1 ; , x2 , ..., xn ),
the scalar product, written z = ax is the image with intensity values zi = axi for all i ∈
{1, 2, ..., n}.
15
2.2 In-Class: Introduction to Radiography and Tomography
Radiography is an imaging technique used to view internal structures of the body that
uses electromagnetic radiation (x-rays) by exposure of film specially sensitized to x-rays or
gamma rays. Tomography is any method that produces images of single tissue planes by
computer processing -think “CAT scan” (computerized axial tomography). This scan is di-
vided into a square matrix of pixels.
Why is it good: noninvasive and has high contrast resolution
Source:http://medical-dictionary.thefreedictionary.com/tomography
If you want to try this out on your own, go to the course’s blackboard site. Click the Labs
link and download the “Source Code for Labs.” Save it to a folder you will be able to find
later. Open Matlab and make sure you are in the correct folder. Note this only works in
MatLab.
RadTomExamples(3) shows the 30 views that were shown in the CAT scan movie. In an
actual CAT scan there are typically hundreds if not over a thousand scans taken in order to
produce the brain images that we saw originally. Question: Why might we want to take
fewer than hundreds of views?
16
RadTomExamples(5) shows a comparison of reconstructions using hundreds of very low
noise (very high exposure) radiographs and advanced Linear Algebra methods (top) and
reconstructions from the 120 low noisy radiographs. The first set of reconstructions is the
ideal reconstruction (very close to the original data). The upshot of this comparison is that
the left-inverse method used for the second reconstruction (developed and implemented by
students in a later lab) is not necessarily the best inversion method when the data is noisy
and when we have some prior knowledge of the object (brain) details.
RadTomExamples(6) shows the series of brain slice reconstructions using only the 30 low
noise radiographs shown previously. This reconstruction uses a noise-sensitive pseudo-inverse
method based on the singular value decomposition of the radiographic transformation (this
is developed and implemented by students in later labs).
RadTomExamples(8) shows the series of brain slice reconstructions using only the 30
low-noise radiographs shown previously. This reconstruction uses a noise-sensitive pseudo-
inverse method and allows radiographic transformation null space contributions that satisfy
prior-knowledge constraints.
17
18
2.3 Lab 2: Radiography and Tomography: Part 1
Grayscale Images
A grayscale image can be associated with a set of numbers representing the brightness of each
pixel. For example, the 2 × 2 pixel image below can be associated with the corresponding
array of numbers, where the black squares represent pixels with intensity 0 and the white
squares represent pixels with intensity 16:
16 8
~ 0 16
Note that this interpretation gives us a way to think about multiplying an image by a
constant and adding two images. For example, suppose we start with the three images (A,
B, and C) below.
Then multiplying Image A by 0.5 results in Image 1 below. Note that the maximum intensity
is now half what it previously was, so the all pixels have become darker gray (representing
their lower intensity). Adding Image 1 to Image C results in Image 2 below; so Image 2 is
created by doing arithmetic on Images A and C.
Image 1 Image 2
19
Image 3 Image 4
Exercise 1: Write Image 3 and Image 4 using arithmetic operations of Images A, B, and
C.
Images in Matlab
We’ll now see how to input matrices, convert them into grayscale images, and display them
in Matlab (or Octave). If you do not have access to Matlab or Octave through academic
or personal computing resources then you may complete this Lab using the online service
octave-online.net (instructions at the end of this writeup).
Exercise 2 Input these lines into the command window of Matlab. Note that ending a line
with a semicolon suppresses the output. If you want to show the result of a computation,
delete the semicolon at the end of its line. Briefly describe what the output of each of these
lines of code gives you. Note: In order to display an image, we have to know the minimum
and maximum pixel intensities. The imshow function allows the user to specify these values.
M_A = [0 0 8 8; 0 0 8 8; 8 8 0 0; 8 8 0 0];
M_B = [0 8 0 8; 8 0 8 0; 0 8 0 8; 8 0 8 0];
M_C = [8 0 0 8; 0 8 8 0; 0 8 8 0; 8 0 0 8];
figure;
subplot(1,3,1), imshow(M_A, [0, 16]),title(’Image A’);
subplot(1,3,2), imshow(M_B, [0, 16]),title(’Image B’);
subplot(1,3,3), imshow(M_C, [0, 16]),title(’Image C’);
Exercise 3: Enter the following lines of code one at a time and state what each one does.
M_A
M_1 = .5*M_A
M_2 = M_1 + M_C
figure;
subplot(1,2,1), imshow(M_1, [0, 16]), title(’Image 1’);
subplot(1,2,2), imshow(M_2, [0, 16]), title(’Image 2’);
20
Exercise 4 Now write your own lines of code to check your conjectures to get Images 3
and 4. How close are these to Images 3 and 4? Be sure to print out your code and submit
it with this lab.
(a) What happens when pixel intensities in an image exceed the display range as input into
the imshow function?
(b) How should we interpret pixel intensities that lie outside our specified range?
(c) What algebraic properties does the set of all images have in common with the set of real
numbers?
Survey Feedback Question: If you are willing to provide feedback for this lab, please fill
out the survey for our study at the following link: http://bit.ly/linearalgebralabs2020
2. Optional: Click the three bars in the upper right of the screen and sign in. This will
be necessary if you complete the next Lab using this service.
3. The rightmost window is the command prompt terminal. You will type your commands
here. You also have the option of creating your own scripts and functions to save and
run.
21
22
3 Lab 3: March Mathness: Using Linear Algebra for
Predictive Modeling
3.1 Pre-Lab
Please read all of sections before 3.2 and answer any questions along the way. Turn in your
pre-lab answers with your Lab 3 write-up.
Linear Algebra can be used in sports analytics. In this lab, we will discuss how we can use
linear algebra to develop sports ranking systems. The most basic way to ranks teams is
through win percentage.
# of games won wi
Recall Win Percentage= = for each team i.
# of games played t1
Why would basing a team’s ranking only by win percentage not necessarily be the best
method for sports ranking?
On reason this may not work well is that there is no way to distinguish strength of schedule.
Team A may only play and win 1 game and thus has a win percentage of 100% while Team
B may play 100 games and win 99 of them which would give them a win percentage of 99%.
If we based teams only by win percentage, we would rank team A over team B. Is this fair?
Similarly if team C plays and wins all 100 games, they have the same win percentage as team
A. Is it fair to give them the same ranking? How can we distinguish between a team that
is undefeated with a difficult schedule verses an undefeated team in a weaker conference? It
turns out linear algebra can help.
1. Why do you suppose that is? How would you rank the teams in this system?
B D
23
2. How would you rank this system of teams?
A E
B D F H
C G
3. The two examples above are easier than most to rank, but often we don’t have such
nice systems for example, suppose we tweak the systems so we have the new systems
below. What challenges come up when trying to rank these? What other information
would you like to know about these teams and systems?
B D
C
or
A E
B D F H
C G
Our goal, as sports analysts, is to determine not only who is number one, but who is number
two, three, four, etc. Sports ranking is similar to Google’s task of ranking pages, but is much
tougher because the outcome of games require both skill and luck.
24
3.1.2 The Colley Method
As part of his mathematics PhD dissertation, Dr. Wesley Colley developed a method to rank teams
in a way that incorporates strength of schedule which can make it a little more accurate than win
percentage [1]. Here’s why. At the start of the season, a team’s winning percentage would 0/0
which is undefined! The Colley Method says an untried team should have a rating of 50%, 50-50
chance the team will win or lose. Colley also wants to have the average of all rating be roughly 0.5
as well. So we adjust how we calculate our win percentage.
wi
Regular Winning Percentage is calculated by , where wi is the total number of wins for
ti
Team i and ti is the total number of games placed by Team i.
wi + 1
The Colley Winning Percentage is calculated as . Since, after each game, the denom-
ti + 2
inator increases by 1, the losers rating will decreasing and the winners rating will increase
after each game.
To set up his system, Colley sets the rating for each team, ri , equal to its Colley win
wi + 1
percentage. That is, ri = . In order to incorporate strength of schedule, Colley does
ti + 2
the following algebraic manipulation (note li denotes the total number of losses for Team i):
wi + 1
ri = (1)
ti + 2
(2 + ti )ri = 1 + wi (2)
wi wi li li
(2 + ti )ri = 1 + + + − (3)
2 2 2 2
wi wi
Note we use the fact that wi = 2
+ 2
and l2i − l2i = 0. Rearranging our equation, we now
get:
wi − li wi + li
(2 + ti )ri = 1 + + (4)
2 2
wi + li
Note that is just the total number of games played by team i divided by 2. This is
2
where Colley made an adjustment to his system in order to incorporate strength of schedule.
wi + li
He does this by replacing with the sum of the ratings of the teams played by team i.
2
Thus our new Colley system has the following set up. For each Team i, we get the following
equation:
wi − li
(2 + ti )ri = 1 + + S, (5)
2
where S is the sum of the ratings of teams played by Team i.
25
Example 3.1. if Team A beat Team B, Team C beat Team A, Team C beat team B, and Team
B beat Team C, using the Colley Method we would have the following system of equations:
1−1
(2 + 2)rA = 1 + + rB + rC
2
1−2
(2 + 3)rB = 1 + + rA + 2rC
2
2−1
(2 + 3)rC = 1 + + rA + 2rB
2
Rearranging the system gives us:
4rA − rB − rC = 1
−rA + 5rB − 2rC = 0.5
−rA − 2rB + 5rC = 1.5
26
3.2 Lab 3: In class portion
Please answer the following questions on a separate piece of paper.
4. Use the Colley method to come up with a rating for the following system.
A
D B
5. Suppose we have the teams, A, B, and C. Team C beats A by 17 points during the
first part of the season. During the middle of the season, Team B beats C by 10 point
and Team A beats B by 10 points. And suppose near the end of the season, Team A
beats B by 5 points. Create and find a rating using the Colley Method.
6. Now that we have explored the Colley System for Rating Teams. What were some of
the strengths and weaknesses of this method?
27
Example 3.2. Suppose I have 3 teams, A, B, and C. Suppose Team A beat Team B by 7,
Team C beat Team A by 1, Team C beat team B by 1, and Team B beat Team C by 10, we
would get the following system of equations:
rA − rB = 7
rC − rA = 1
rC − rB = 1
rB − rC = 10
8.
Use least squares
to solve
the following inconsistent solution.
1 −1 0 10
0 1 −1 1
r= .
−1 0 1 17
1 −1 0 5
9. We now have a new problem: This system has infinitely many solutions. To fix this,
we replace the last row of our new matrix with all 1’s and the last entry in the vector
with 0. We won’t go into the technical details for why we do this, but this adjustment
forces the ratings to sum to 0.
Do this and solve the new system.
10. The Colley and Massey Rating Methods are good, but what are some other things we
may want to consider when making our ranking?
Example 3.3. Easy Adjustment for blowouts: Suppose you want to balance out any
blow-outs from the games. This is quite easy with the Massey Method. Suppose you want to
consider any game in which one team beats the other team by 15 points or more a blow out
and count them all the same. We would just adjust our Massey System by capping the size
of the win.
28
3.2.2 Adding Weights to Colley and Massey Systems
We can weight both of these rating system to give us a more personalized rating. The key
now is that we count total weighted games and weighted scores. Weighted Massey
Example 3.4. Suppose Team A beat Team B by 7 mid season, Team C beat Team A by 1
early in the season, Team C beat Team B by 1 mid-season, and Team B beat Team C by 10
late in the season. Suppose we want to weight early games by 0.5, mid games by 1, and late
games by 5.
Solution: Using a normal, unweighted Massey system with a 10 point cap with the columns
representing teams A, B, and C respectively and the rows representing games 1, 2, 3, and 4,
we would have the following system:
1 −1 0 7
−1 0 rA
1 1
Xr = b ⇒ 0 −1 1 · rB = 1
(8)
rC
0 1 −1 10
When we use the Massey system, we can actually use something called a Weight Matrix,a
diagonal matrix in which each diagonal entry (i, i) is equal to the weight for that given
game/ We multiply this matrix to both sides of Equation 8 (the equation above) by our
weight matrix: W Xr = W b:
1 0 0 0 1 −1 0 1 0 0 0 7
0 1 0 0 −1 0 rA
·
1 0 1 0 0 1
0 0 2 0 0 −1 1 · rB = 0 0 2 0 · 1 (9)
rC
0 0 0 5 0 1 −1 0 0 0 5 10
Which gives us
1 −1 0 7
−1 0 rA
1 1
0 −2 2 · rB = 1 (10)
rC
0 5 −5 50
Next we set up the least squares solution:
1 −1 0 7
1 −1 0 0 −1 0 rA 1 −1 0 0
−1 0 −2 5 · 1 ·1
0 −2 2 · rB = −1 0 −2 5 1 (11)
0 1 2 −5 rC 0 1 2 −5
0 5 −5 50
This gives us
2 −1 −15 rA 6
−1 30 −29 · rB = 239 (12)
−1 −29 30 rC −245
29
After replacing the last row or our matrix with 1’s and 0, we get:
2 −1 −15 rA 6
−1 30 −29 · rB = 239 (13)
1 1 1 rC 0
Example 3.5. Suppose we have the same teams, A, B, and C where Team C beats A by 17 points
during the first part of the season. During the middle of the season, Team B beats C by 10 points
and Team A beats B by 10 points. And suppose near the end of the season, Team A beats B by 5
points. Create and determine the weighted Colley rating by weighting the time of the game. Use
the weighting where the first part of the season is weighted by 0, the middle by 1, and the end of
the season by 1.5. Recall we already did this ranking without weights in Example 5.
Solution: Recall, to set up the Colley System, the diagonal entries (i, i) are given by (2+
the number of total weighted games the team has played). The off diagonal entries (i, j)
are given by (−1)· (number of weighted games team i has played team j). b is given by
ŵi + lˆi
bi = 1 + where ŵi is the number of weighted wins and lˆi is the number of weighted
2
losses for team i.
So for example, Team A has played 1 early game, 1 mid-season game, and 1 late games
which means they have played a total of 1 · 0 + 1 · 1 + 1 · 1.5 = 2.5 total weighted games.
Team B has played 0 early games, 2 mid-season games, and 1 late game which means they
have played a total of 0 · 0 + 2 · 1 + 1 · 1.5 = 3.5 total weighted games.
Team C has played 1 early game, 1 mid-season game, and no late games which means they
have played a total of 1 · 0 + 1 · 1 + 0 · 1.5 = 1 total weighted games.
30
More Exercises:
10. In the weighted examples above, did we have different rankings than the unweighted
Colley or Massey? What do you think accounted for this (either staying the same or
changing)?
11. Draw the directed graph for the following system and use the Colley Method to rank
the following teams Team A beats E once and C twice. Team B beats C once. Team
D beats B once, C once, and E once. E beats C once and B twice.
12. Now use a weighted the Colley Method which ranks games won (loss) early in the
season as 0.5 wins (losses), games won in the mid-season ranked as 1 win (loss) , and
games won late in the season as 1.5 wins (losses) to rank the following system:
During the Early Part of the Season:
Team B beats C once. Team D beats E once and C once. Team E beats B once.
During the Middle Part of the Season:
Team A beats C once. Team D beats B once. Team E beats C once
During the Later Part of the Season:
Team A beats E once and C once. Team E beats B once.
13. Draw the directed graph for the following system and use an unweighted the Massey
Method with a 10 max point differential to rank the following system:
During the Early Part of the Season: Team B beats C by 8 points. Team D beats
E by 5 points.
During the Middle Part of the Season:
Team A beats D by 10 points. Team E beats C by 5 points.
During the Later Part of the Season:
Team A beats E by 4. Team E beats B by 20 points.
14. Create your own weighted rating system for a system with at least 3 teams and find a
ranking for your teams.
15. Bonus: Use a weighted Massey Method which ranks games won (loss) early in the
season as 0.5 wins (losses), games won in the mid-season ranked as 1 win (loss) , and
games won late in the season as 1.5 wins (losses) to rank the following system from
the previous problem.
16. If you are willing to provide feedback for this lab, please fill out the survey for our
study at the following link: http://bit.ly/linearalgebralabs2020
End of Lab. There are extra examples of Massey and Colley Systems are on the next page.
31
3.2.3 Extra Examples of Massey and Colley
Example 3.6. Suppose Team A beats Team B by 5, Team C beat Team A by 1, Team C
beat Team B by 1, and Team B beat Team C by 10. Rank these teams using the unweighted
Massey Method.
rA − rB = 7
rC − rA = 1
rC − rB = 1
rB − rC = 10
32
ratings of the teams should add up to 0. After this adjustment, we can now solve the system.
2 −1 −1 rA 6
−1 3 −2 · rB = 2 (18)
1 1 1 rC 0
Example 3.7. Now suppose we want to set up the same weighted system as above using the Massey
Method. Suppose Team A beat Team B by 5 mid season, Team C beat Team A by 1 early in the
season, Team C beat team B by 1 mid-season, and Team B beat Team C by 10 late in the season.
Suppose we want to weight early games by 0.5, mid games by 1, and late games by 3. Find a ranking
for the teams using a weighted Massey System.
Solution: Notice when we incorporate weights into the Massey system, it is a little easier than
with the Colley Method since we can use a weight matrix. This weighted matrix is a diagonal
matrix in which each diagonal entry (i, i) is equal to the weight for that given game. Thus we can
start with the same original matrix system for Massey, but multiply both sides of the equation by
our weight matrix, W Xr = W b:
1 0 0 0 1 −1 0 1 0 0 0 7
0 0.5 0 0 −1 0 r A 0 0.5 0 0 1
1
0 0 1 0 · 0 −1 1 · rB = 0 0 1 0 · 1 (19)
rC
0 0 0 3 0 1 −1 0 0 0 3 10
Which gives us
1 −1 0 7
−0.5 0 0.5 rA 0.5
· rB = (20)
0 −1 1 1
rC
0 3 −3 30
Next we set up the least squares solution:
1 −1 0 7
1 −0.5 0 0 −0.5 0 0.5 rA 1 −0.5 0 0 0.5
−1 0 −1 3 · 0
· rB = −1 0 −1 3 · (21)
−1 1 1
0 0.5 1 −3 rC 0 0.5 1 −3
0 3 −3 30
33
This gives us
1.25 −1 −0.25 rA 6.75
−1 11 −10 · rB = 82 (22)
−.25 −10 10.25 rC −88.75
After replacing the last row or our matrix with 1’s and 0, we get:
1.25 −1 −0.25 rA 6.75
−1 11 −10 · rB = 82 (23)
1 1 1 rC 0
rA 5.314
Solving this gives us: rB = 1.627 Which gives us the ranking: Team A, Team B, Team C.
rC −6.941
Example 3.8. Suppose we have teams A, B, and C where Team C beats A by 17 points during the
first part of the season. During the middle of the season, Team B beats C by 10 points and Team
A beats B by 10 points. And suppose near the end of the season, Team A beats B by 5 points. Find
the rating using a weighted Massey Method in which we use the weights 0 for an early game, 0.5
for a mid-season game and 1 for a game played late in the season and we use a 10 point cap.
Solution: Using a normal, unweighted Massey system with a 10 point cap with the columns
representing teams A, B, and C respectively and the rows representing games 1, 2, 3, and 4, we
would have the following system:
−1 0 1 10
0 1 −1 10
1 −1 0 r = 10 (24)
1 −1 0 5
When we use the Massey system, we can actually use something called a Weight Matrix and
multiply it to both sides of Equation 24 (the equation above). Thus we get:
0 0 0 0 −1 0 1 0 0 0 0 10
0 0.5
0 0 0 1 −1
0 0.5 0 0 10
r= (25)
0 0 0.5 0 1 −1 0 0 0 0.5 0 10
0 0 0 1 1 −1 0 0 0 0 1 5
We now get the weighted Massey system M̃ r = b̃:
0 0 0 0
0 0.5 −0.5 5
r = (26)
0.5 −0.5 0 5
1 −1 0 5
34
Next we find the Least Squares Solution to this system :M̃ T M̃ r = M̃ T b̃:
0 0 0 0
0 0 0.5 1 0 0 0.5 1
0 0.5 −0.5 −1 0 0.5 −0.5 r = 0 0.5 −0.5 −1 5
0.5 (27)
−0.5 0 5
0 −0.5 0 0 0 −0.5 0 0
1 −1 0 5
Example 3.9. Suppose Team A beats Team B by 5, Team C beat Team A by 1, Team C beat team
B by 1, and Team B beat Team C by 10. Use the unweighted Colley Method to rank the following
teams.
Solution: Using the Colley Method, we would set up the following system of equations:
1−1
(2 + 2)rA = 1 + + rB + rC
2
1−2
(2 + 3)rB = 1 + + rA + 2rC
2
2−1
(2 + 3)rC = 1 + + rA + 2rB
2
Rearranging the system gives us:
4rA − rB − rC = 1
1
−rA + 5rB − 2rC =
2
3
−rA − 2rB + 5rC =
2
Solving this nice symmetric system gives us the following matrix system, Cr = b:
4 −1 −1 rA 1
−1 5 −2 · rB = 1 (30)
2
3
−1 −2 5 rC 2
35
rA 0.5
Solving this system gives us rB = 0.42857. Putting the ratings in order from largest to
rC 0.57143
smallest, we get the following ranking: Team C first, Team A second, and Team B third.
Example 3.10. Suppose we have the same system as in Example 3.9: Team A beat Team B by 5,
Team C beat Team A by 1, Team C beat team B by 1, and Team B beat Team C by 10. But now
suppose we wanted to weight the time in the season in which these teams played. Suppose Team A
beat Team B by 5 mid season, Team C beat Team A by 1 early in the season, Team C beat team
B by 1 mid-season, and Team B beat Team C by 10 late in the season. Suppose we want to weight
early games by 0.5, mid games by 1, and late games by 3. Find the ranking for these teams using
this weighted Colley Method.
36
4 Lab 4: Radiography and Tomography Part 2
4.1 Pre-Lab 4
Read the following pages entitled “Transmission Radiography and Tomography: A Simplified
Overview” as a prerequisite to Lab 2. You may not understand everything from this handout,
but I would like you to look for the linear algebra in the methods and try to get a general overview
of the Radiography Process. You do not need to fully understand anything else besides
the linear algebra concepts that come up. I have included the following question for you to
answer to help guide you in your reading (below) along with the goals and summary of terminology
of what you should get out of the reading after the reading section.
• To recognize and appreciate that, sometimes, complex phenomena can be reasonably modeled
with straightforward mathematics.
2. What is accomplished in the matrix multiply when multiplying an object vector by the k th
row of T?2
2
More questions on back!
37
3. Explain how you change the radiographic operator when changing from one view to many.
4. Why do we use pixel values βk where βk is defined as βk ≡ −α ln( ppk0 ) instead of the expected
photon count pk ?
38
DRAFT: Radiography/Tomography c 2016 T. Asaki, C. Camfield, H. Moon, M. Snipes
This material provides a brief overview of radiographic principles for the model in Lab #2 of
the Radiography and Tomography Linear Algebra Modules. The goal is to develop the basic
discrete radiographic operator for axial tomography of the human body. To accomplish this
goal, it is not necessary to completely understand the details of the physics and engineering.
We wish to arrive at a mathematical formulation descriptive of the radiographic process and
establish a standard scenario description with notation.
What is Radiography?
Transmission radiography and tomography are familiar and common processes in today’s
world, especially in medicine and non-destructive testing in industry. Some examples include
• Single-view X-ray radiography is used routinely to view inside the human body; for
example, bone fracture assessment, mammography, and angiographic procedures.
• Neutron and X-ray imaging is used in industry to quantify manufactured part assem-
blies or defects which cannot be visually inspected.
X-rays, just like visible light, are photons or electromagnetic radiation, but at much higher
energies and outside of the range of our vision. Because of the wavelength of typical X-
rays (on the order of a nanometer), they readily interact with objects of similar size such as
individual molecules or atoms. This property makes them particularly useful in transmission
imaging. Figure 1 is a cartoon of a typical x-ray radiographic experiment or procedure. An
x-ray beam is produced with known energy and geometric characteristics. The beam is
aimed at a region of interest. The photons interact with matter in the region of interest,
changing the intensity, energy and geometry 39 of the beam. A detector measures the pattern
1
DRAFT: Radiography/Tomography c 2016 T. Asaki, C. Camfield, H. Moon, M. Snipes
E(0, y, z) E(Dx , y, z)
ρ(x, y, z)
Transmitted Detector
x−ray Incident Region of Interest
x−ray beam
Source x−ray beam
(and possibly the distribution) of incident energy. The detection data, when compared to
the incident beam characteristics, contains the known signature of the region of interest.
We consider the mathematics and some of the physics involved in each step with the goal
of modeling a radiographic transformation appropriate for mixed soft and hard tissue axial
tomography of the human body.
2
DRAFT: Radiography/Tomography c 2016 T. Asaki, C. Camfield, H. Moon, M. Snipes
dx
+
x
D
x
x
0
ρ(x)
E
E )
E
E
(x
(x
(D
(0
)
x
)
dx
)
dE(x) = E(x + dx) − E(x) = µρ(x)E(x)dx
Figure 2: X-ray beam attenuation computation for a beam path of fixed y and z.
the same as the itensity at the source. We write both as E(0, y, z). It is assumed that this
quantity is well known or independently measureable.
dE(x, y, z) 41
= −µρ(x, y, z)dx
E(x, y, z)
3
DRAFT: Radiography/Tomography c 2016 T. Asaki, C. Camfield, H. Moon, M. Snipes
Z E(Dx ,y,z) Z Dx
dE(x, y, z)
= −µ ρ(x, y, z)dx
E(0,y,z) E(x, y, z) 0
Z Dx
ln E(Dx , y, z) − ln E(0, y, z) = −µ ρ(x, y, z)dx
0
R Dx
E(Dx , y, z) = E(0, y, z)e−µ 0 ρ(x,y,z)dx
.
This expression shows us how the initial intensity is reduced, because photons have
been scattered out of the beam. The relative reduction depends on the density (or mass)
distribution in the region of interest.
Let the bin cross sectional area, σ, be small enough so that both the contributions of the
density and intensity to the bin area integration are approximately a function of x only.
Then
σE(0, yk , zk ) −µ R Dx ρ(x,yk ,zk )dx
pk = e 0 ,
hν
where yk and zk locate the center of bin k. Let p0k be the number of x-ray photons initially
aimed at bin k, p0k = σE(0, x, y)/hν. Due to attenuation, pk ≤ p0k for each bin.
R Dx
pk = p0k e−µ 0 ρ(x,yk ,zk )dx
.
Equivalently, we can write (multiply the exponent argument by σ/σ):
µ R Dx
pk = p0k e− σ 0 σρ(x,yk ,zk )dx
.
The remaining integral is the total mass in the region of interest that the x-ray beam passes
through to get to bin k. We will call this mass sk . Now we have
pk = p0k e−sk /α ,
where α = σ/µ. This expression tells us that the number of photons in the part of the beam
directed at bin k is reduced by a factor that is exponential in the total mass encountered by
the photons.
Finally, we note that the detector bins correspond
42 precisely to pixels in a radiographic
image.
4
DRAFT: Radiography/Tomography c 2016 T. Asaki, C. Camfield, H. Moon, M. Snipes
region of interest
detector
Pixel
beam path k
k
Voxel j
PN
Sk = j=1 Tkj xj
or equivalently,
XN
pk
bk ≡ −α ln 0 = Tkj xj .
pk j=1
The new quantities bk represent a variable change that allows us to formulate the matrix
expression for the radiographic transformation
b =43T x.
5
DRAFT: Radiography/Tomography c 2016 T. Asaki, C. Camfield, H. Moon, M. Snipes
Figure 4: Example axial radiography scenario with six equally spaced views. Horizontal
slices of the object project to horizontal rows in the radiographs.
This expression tells us that given a voxelized object mass distribution image x ∈ RN , the
expected radiographic data (mass projection) is image b ∈ Rm , with the two connected
through radiographic transformation T ∈ Mm×N (R). The mass projection b and actual
photon counts p and p0 are related as given above. It is important to note that bk is defined
only for pk > 0. Thus, this formulation is only valid for radiographic scenarios in which
every radiograph detector pixel records at least one hit. This is always the case for medical
applications which require high constrast and high signal-to-noise ratio data.
6
DRAFT: Radiography/Tomography c 2016 T. Asaki, C. Camfield, H. Moon, M. Snipes
Model Summary
The list below gathers the various mathematical quantities of interest.
45
7
DRAFT: Radiography/Tomography c 2016 T. Asaki, C. Camfield, H. Moon, M. Snipes
Model Assumptions
The radiography model we have constructed is based on a number of approximations and
assumptions which we list here. This list is not comprehensive, but it does gather the most
important concepts.
8
DRAFT: Radiography/Tomography c 2016 T. Asaki, C. Camfield, H. Moon, M. Snipes
Additional Resources
There is a variety of online source material that expands on any of the material presented
here. Here are a few starting points.
https://www.nde-ed.org/EducationResources/CommunityCollege/Radiography/cc_rad_index.htm
http://web.stanford.edu/group/glam/xlab/MatSci162_172/LectureNotes/01_Properties%20&%20Safety.pdf
http://radiologymasterclass.co.uk/tutorials/physics/x-ray_physics_production.html
9
4.1.3 Summary of Terminology from the Reading Assignment:
It may be useful to have this out as a reference during Lab 2. As this lab follows the lecture on the
physics of radiography, much of this material is review from your reading, but is provided here for
clarity and continuity. It is important to keep the notation consistent. There are several details to
keep in mind:
Pixel versus Voxel. “Voxel” is the standard term for a general multi-dimensional pixel – a
hyperpixel. In this Lab, for consistency of language, we use “voxel” whenever we are considering
the area of interest (or object) and we use “pixel” whenever we are considering the radiograph.
Square Voxel Array. The total number of voxels is N = n2 . This is a simplification. There is
no theoretical or application limitation that requires the use of a square grid of square voxels. In
general the area of interest can be partitioned in any finite fashion. We have chosen an n × n grid
for computational and visual simplicity.
Voxel and Pixel Size. Voxels are of unit size. This is a choice that makes the computations and
discussion simpler. In quantitative applications, one must be careful to use correct units. Pixel size
is given in terms of the voxel size by specifying the scale factor ScaleF ac. This units simplification
does not alter the quality or details of computational results – quantitative application results differ
only by a multiplicative constant. One can think of this as working in unfamiliar units.
Limitations on n and m. Both n and m must be non-negative even integers. This is only
because this makes the code tomomap.m easier to compose and compute. If the student attempts
to use an odd integer for n or for m the code will stop and report an error message.
Radiographs Arrangement. Each radiograph has the same number of pixels, m. This is an-
other simplification that makes computations simpler. In practice, radiographic angles are imposed
by either rotating the object or rotating the source-detector combination, and taking individual
radiographs at separate times. There is nothing special about measuring radiographic angles in
degrees east of south. This is just the way the module code tomomap.m was written. Notice that
for each radiograph, the center point of the object grid projects perpendicularly to the center point
of the radiograph.
Visual Setup. Keep in mind that in applications the detectors are much more distant from the
area of interest as would be indicated in the figures. All radiographs are typically taken equidistant
from the object.
48
4.2 Lab 4: Radiography and Tomography: Part 2
An Abbreviated View of Radiography
E(0, y, z) E(Dx , y, z)
ρ(x, y, z)
Transmitted Detector
x−ray Incident Region of Interest
x−ray beam
Source x−ray beam
Figure 2: Typical radiographic experiment. The function E measures intensity of the x-ray
beam.
49
region of interest
detector
Pixel
beam path k
k
Voxel j
PN
Sk = j=1 Tkj xj
50
ba·m
x1 xn+1 x2n+1 . . . x1 xn+1 x2n+1 . . .
x2 x2
.. .
. ..
x3 x3
. .
. .
. .
b2m
xn−1 x2n−1 xn−1 x2n−1
b1 b2 bm b1 b2 bm θ2
bm+2
Angles are measured in
bm+1 degrees east of south
Figure 1: The geometry of a single view Figure 2: The Geometry of a multiple view
radiographic transformation. radiographic transformation showing view
1, view 2, and view a.
A First Example
Let’s look at a specific scenario. For the setup pictured below, we have:
10
51
.
52
In Class Example:
We will first do an example together in class. Suppose you have the setup where
• Number of views: a = 2
3. Repeat step (b) using the code tomomap. You will need to use the function tomomap.m found
in blackboard under Lab 2 code.
53
.
54
Radiography and Tomography Lab 2
Now it’s your turn! Whatever you do not finish, you will need to finish outside of class.
The due date for this lab is 1 week after we have started it, unless the instructor
chances the due date. If you are working with a partner, please only submit ONE lab
with both of your names! There are 2 parts to this lab. Complete Parts I and II.
Note: Some of the following exercises will ask you to use Matlab or Octave to compute radio-
graphic transformations. You will need to use the function tomomap.m found in blackboard under
Lab 2 code.
4 3 0 1
6 1 1 0
x= y=
55
2. Suppose you have the setup where
56
Part II: Radiographs of Linear Combinations of Objects
4 3 0 1
6 1 1 0
x= y=
For both of the assigned transformations, T in questions 1 and 2 from Part I above, answer
the following questions.
5. If you are willing to provide feedback for this lab, please fill out the survey for our study at
the following link: http://bit.ly/linearalgebralabs2020
57
58
5 Lab 5: Translation and Rotation Matrices
5.1 Pre-Lab 5
In preparation for this lab, please watch this video https://youtu.be/ysOEnGg_rz0 and
then answer the following questions. The video starts with Translation and Rotation
Matrices, and discusses homogeneous coordinate representations around the 14:55
time stamp.
1. Find a 2 by 2 matrix that reflects the point (x, y) about the x axis.
2. Find a 2 by 2 matrix that scales the point (x, y) by 0.5 in the x direction and 3 in the y
direction.
3. Find a 3 by 3 matrix that scales the point (x, y, z) by 2 in the x direction and 4.5 in the
direction, but does not adjust the scaling of the y direction.
4. Find 3 different homogeneous coordinate representations for the Cartesian point (1, −2).
59
5.2 Lab 5 In-Class Portion
5. Rewrite your matrices found in questions 1 and 2 from the Pre-Lab if we were using the
homogeneous coordinate point (x, y, 1). (You should have 3 by 3 matrix.)
6. At the end of the video, we discussed how we can rotate the point (x, y, 1) about the point
(a, b) by θ degrees counterclockwise by using this matrix multiplication:
1 0 a cos θ − sin θ 0 1 0 −a
M = 0 1 b sin θ cos θ 0 0 1 −b
0 0 1 0 0 1 0 0 1
Simplify this matrix multiplication to 1 matrix (instead of 3) and then use it to rotate the
point (4, 2) 90◦ about the point (1, 1).
60
Translation and Rotation Matrices for 3D
Wireframe models are often digitally create an object in a computer since they can easily be ro-
tated, translated, and scaled using matrix multiplication. These wireframe models are used for
3D printing, movie/video game animations, simulations to determine aerodynamics, and more. To
create a wireframe we need to find the coordinate of each point and determine which vertices are
connected with lines (which creates a system of vectors). We can store all the coordinates of our
vertices in the rows of a matrix. So for example, if we have 300 vertices, our matrix will have 3
rows and 300 columns. If we represent our points in homogeneous coordinates, we would have 4
rows and 300 columns. We can generalize our results from Translation and Rotation Matrices in
2D to 3D to find matrices to rotate and translate these wireframes.3
First we need to represent a wireframe using homogeneous coordinates. Recall, homogeneous point
(x, y, z, h) corresponds with the point ( hx , hy , hz ) in 3-space.
3
For Some great CAD Notes: See Dr Shriram Hegde’s course site: http://web.iitd.ac.in/~hegde/
Images from this assignment are from his course notes.
61
Uniform Scaling:
Want to scale
our cube by s?
1 0 0 0
0 1 0 0
Use Ts =
0 0 1 0.
0 0 0 s
Note that if s < 1 our cube becomes uniformly larger. If s > 1 our cube shrinks uniformly.
0 2 2 0 0 2 2 0
0 0 3 3 0 0 3 3
7. Multiplying our cube by T2 · M = 1 1 1 1 0 0
.
0 0
2 2 2 2 2 2 2 2
Note our s = 2 so T2 uniformly shrinks our cube. Why is this? [Hint: convert from homoge-
neous coordinates to (x, y, z)]
Non-Uniform/local Scaling:
Want to scale
our cube by different values for each direction?
a 0 0 0
0 e 0 0
Use Ts ∗ =
0 0 j 0.
0 0 0 1
Where a scales the x coordinate, e scales the y coordinate, and j scales the z coordinate.
Translation Matrices:
To translate
your wireframe
by p in the x direction, q in the y direction, and r in the z direction
1 0 0 p
0 1 0 q
use: Tt =
0 0 1 r
0 0 0 1
62
If you are interested in learning more -like how the shear a wireframe or move your wireframe
about an arbitrary axis, etc. we encourage you to go to Dr Shriram Hegde’s homepage http:
//web.iitd.ac.in/~hegde/ Go to Courses → Computer Aided Design → Course Notes → Lecture
6.
9. Find the translation matrix to move your cube by 1 in the x direction, -1 in the y direction,
and 2 in the z direction.
Rotation Matrices:
To Rotate an image θ degrees about the following axis (using homogeneous coordinates):
1 0 0 0
0 cos θ sin θ 0
x-axis: Rx (θ) =
0 − sin θ cos θ 0
0 0 0 1
cos θ 0 − sin θ 0
0 1 0 0
y-axis: Rx (θ) =
sin θ 0 cos θ 0
0 0 0 1
cos θ sin θ 0 0
− sin θ cos θ 0 0
z-axis: RZ (θ) =
0
0 1 0
0 0 0 1
10. What is the rotation matrix that will rotate our cube 90 degrees about the y axis?
63
Note: Remember, just like with 2D objects, we can multiply matrices together to get multiple
movements of our wireframes.
Below is Octave code for rotating a 2D-point 90 degrees counterclockwise:
11. With this as a guide, write code that will rotate the point (1, 7) by 270 degrees counterclock-
wise. You can fill in the blanks below as to what you type.
% Create rotation matrix
theta = ; % to rotate counterclockwise
R = [cosd(theta) -sind(theta); sind(theta) cosd(theta)];
% Rotate your point
point = [ ; ]; % arbitrarily selected
rotpoint = R*point;
12. For the previous question, what did you get as an output for rotpoint?
13. Write code below that would rotate a point 270 degrees clockwise.
14. If you are willing to provide feedback for this lab, please fill out the survey for our study at
the following link: http://bit.ly/linearalgebralabs2020
64
5.3 Bonus Questions
Follow along with the tutorial at https://www.mathworks.com/help/symbolic/examples/rotation-
matrix-and-transformation-matrix.html in order to answer the following questions.
15. At the beginning of the tutorial, you are shown how to plot a certain parametric surface.
Write code that will rotate that parametric surface about the y-axis by 60 degrees counter-
clockwise. Attach that code and the image that you obtain to this lab. If you have, write
”See Attached” below.
16. Near the middle to end of the tutorial, you are shown how to scale the parametric surface
as well as rotate it. Write code that will first scale that parametric surface by 0.5 in the
x-direction and by 2 in the y-direction, then will rotate the scaled surface about the x-, y-,
and z-axis by 30 degrees counterclockwise, in order z, then y, then x. Attach that code
and the image that you obtain to this lab. If you have, write ”See Attached” below.
65
66
6 Lab 6: Radiography and Tomography Lab Part 3
6.1 Pre-Lab 6
This lab will motivate some of the computational techniques we will use to determine properties of
transformations in addition to putting these properties into a real world context.4 Please review
the misconsceptions below and the In-Class example and then answer the questions on the next
page. Do not worry if you get stuck, but try to answer each question.
In Part 2 of the Radiography and Tomography Lab, you found several radiographic transformation
operators. The object image consisted of four (or in one case, sixteen) voxels and was represented
as a vector in R4 . The radiographic image was represented as a vector in RM , one entry for
each radiographic pixel. The price we pay for this representation is that we no longer have the
geometry of the radiographic setup encoded in the representation. The use of representations in Rn
is a computational tool and not geometrically descriptive of vector spaces of images. We want to
reiterate that this is only a representation and that these images are not vectors in RM . Because
of these new image representations, each transformation could be constructed as a matrix operator
in MM ×4 (R).
4
Radiography/Tomography c 2016 T. Asaki, C. Camfield, H. Moon, M. Snipes
67
In Class Example:
Consider the radiographic setup described below.
b4
x1 x3 (Total voxels N = 4)
• Pixels per view in radiograph: m = 2
b3 • ScaleF ac = 1
x2 x4
• Number of views: a = 2
• Angle of the views: θ1 = 0◦ , θ2 = 90◦
b1 b2
1 1 0 0
0 0 1 1
The transformation matrix for this map is T =
0
.
1 0 1
1 0 1 0
68
2. Describe the set of all invisible objects. This could involve an equation that the entries would
have to satisfy or a few specific objects that could be used to construct all other such objects.
Be creative.
3. a) Is it possible for two different objects to produce the same radiograph? If so, give an
example.
69
b) Choose any two objects that produce the same radiograph and subtract them. What is
special about the resulting object?
4. Are there radiographs (in the appropriate dimension for the problem) that cannot be pro-
duced as the radiograph of any object? If so, give an example.
70
5. Describe the set of radiographs that can be produced from all possible objects. This may
require similar creativity.
6. Show that the set of all invisible objects is a subspace of the vector space of all objects.
71
7. Find a set of objects that spans the space of all invisible objects. Is your set linearly inde-
pendent? If not, find a linearly independent set of objects that spans the space of invisible
objects. The linearly independent set you have found is a basis for the space of invisible
objects.
8. The set of all possible radiographs is a subset of a vector space. What is this vector space?
Show that the set of all possible radiographs is a subspace of this vector space.
72
9. Find a basis for the set of all possible radiographs. That is, find a linearly independent set
of radiographs that spans the space of possible radiographs.
Summary:
73
6.2 Lab 6 Questions
Now it’s your turn! For each of the two setups (B and C) below, Answer the following questions.
In looking at more examples you will get a better sense of the underlying principles at work. We
will use your observations to develop deeper linear algebra theories. Whatever you do not finish
in class, you will need to finish outside of class. The due date for this lab is 1 week after we have
started it, unless the instructor chances the due date. If you are working with a partner, please
only submit ONE lab with both of your names!
Setup B
b4
The Transformation
1 for this map is
1
2 1 0 2
1 0 1 1
b3
T = 2
1 1 1 0
2
x1 x3 2 2
0 12 12 1
• ScaleF ac = 2/2
• Number of views: a = 1
b1
Setup C
1
0 2 0 0
x1 x3 1 1
0 1
2 2 2 .
1
0 1 1
2 2 2
1
0 0 2 0
x2 x4
b4
(Total voxels N = 4)
b2
• Number of views: a = 2
The Transformation for this map is T = • Angle of the views: θ1 = 90◦ , θ1 = 315◦
74
Questions for Each Setup
Answer the following questions for Set Up B and Setup C. First answer questions for Set up B then
answer all questions for Setup C (to help with grading). Then answer the general questions below.
Thanks!
1. Describe the set of all invisible objects by finding a basis for this space. Are any nonzero
objects invisible to this operator? If so, give an example. (See your Pre-Lab for the definitions:
nonzero object and invisible object.)
2. Is it possible for two different objects to produce the same radiograph? If so, give an example
and subtract them. What is special about the resulting object?
3. Describe the set of radiographs that can be produced from all possible objects.
4. Are there radiographs (in the appropriate dimension for the problem) that cannot be pro-
duced as the radiograph of any object? If so, give an example.
5. Find a basis for the space of all possible radiographs. That is, find a linearly independent
set of radiographs that spans the space of possible radiographs.
Question: In this lab, you found bases for two different vector spaces (invisible objects, and
possible radiographs). What reasons might you be interested in these bases, in the context of
radiography?
Survey Feedback Question : If you are willing to provide feedback for this lab, please fill out
the survey for our study at the following link: http://bit.ly/linearalgebralabs2020
Bonus Question: Can you find a radiographic setup for square objects with 4 voxels so that there
are no invisible objects? What properties must the associated linear transformation have?
75
76
7 Lab 7 - Applications of Markov Chains and Singular
Value Decomposition
7.1 Pre-Lab Reading: Applications of SVD
Singular values appear in many linear algebra applications like clustering (eigenvectors help with
this too!), statistics, signal processing, and other applications that involve big data. If we had an
Applied Linear Algebra II course (oh boy!) we would go into more examples of these applications,
but for now we will just discuss one major application and discuss a more general use of SVD which
will give some insight regarding its importance for applications which use big data.
As we have seen in our radiography/tomography labs, Matrices can be used to store and transfer
digital images. SVDs of matrices can help use complete these processes efficiently. That is, SVDs
can help reduce redundant information inside an image. They do this by takinge advantage of the
fact that pixels near one another in a picture often have similar greyscale levels. Thus it may be
possible to represent the image using less storage space while still keeping the essential parts of the
picture. Now SVD isn’t always the typical method used in data compression algorithms. There are
other methods and versions of SVD which do an even better job. Nevertheless, Singular Value De-
composition still gives us an idea about how image compression can be done and why it sometimes
leads to blurrier pictures than the original. SVD also is used in Principle Component Analy-
sis, a technique to organize analyze multivariate data (and can used for face recognition algorithms
and merging of pictures of faces). Unfortunately, we do not have time to cover this interesting topic.
The terms with the largest singular values contain most of the “data” or information about the
image whereas smaller singular values don’t contribute as much. So the idea is, we can sometimes
discard many of these smaller low singular value terms, and still get a good approximation of our
original image. Thus we can have A ≈ σ1 u1 v1T + σ2 u2 v2T + ... + σk u1 kvkT for k < n.
5
Images from our text When Life is Linear
77
Example: If an image has m by n pixels, the storage requires m · n numbers.
But if we approximate A with k singular values, A ≈ σ1 u1 v1T +σ2 u2 v2T +...+σk uk v1 k T , this requires
only (m + n) numbers! Savings Galore!
1. Change the values for k. and see how that changes the picture. Use the Snip tool to attach
pictures of the images which you get using 1 singular value, 20, 50, and 100 to your lab
report.
78
7.3 Example 2: Approximating Matrix Rank
Most numerical calculations used in solving Ax = b are as reliable as they can be when we use
the Singular Value Decomposition for A. We have mentioned before that orthogonal matrices are
nice and stable. That means that they do not affect lengths of vectors or angles between vectors,
which decreases the likelihood of error. It also means that small changes to the data will not cause
large changes to the solutions to the system. What this means is that the U and V T vectors in
the SVD of A, don’t have the errors. These errors are stored in Σ. If the singular values of A
are super, super small, it is often really difficult to avoid roundoff error. We can approximate or
anticipate error by calculating something called the condition number of a matrix. This condition
number affects the sensitivity of a solution to Ax = b to errors/changes in the entries of A -that is
it affects the stability of A. This condition number can be calculated many different ways, but the
most commonly used calculation is the ratio of the largest and smallest singular value of A.
σ1
Definition 7.1. If A is an invertible n × n matrix, then the ratio of σn of the largest and smallest
singular values of A gives us the condition number of A.
Numerical Note: The larger the condition number, the closer the matrix is to being singular
(that is, non invertible). For example, condition number of In is 1 and a non-invertible matrix
has an infinite condition number. If a matrix is really closed to be being singular, we say it is
ill-conditioned. Ill-conditioned matrices can become singular if some of the entries are changed
very slightly -which means they are in trouble if we have round-off error!
3. We can use the condition number of a matrix to estimate the accuracy of a solution to Ax = b.
Supposed the condition number of A is 10k (k > 0) and A and b are accurate to r significant
digits, then the calculated solution to Ax = b should be accurate to at least r − k significant
digits. Suppose we the condition number of A is 1, 000 and A and b are accurate to 12 digits.
How accurate will the solution to Ax = b be?
Definition 7.2. Round-off error also affects a computer’s ability to determine the rank of a matrix.
The numerical rank of a matrix is the perceived rank of a matrix by a computer.
Definition 7.3. The “Machine epsilon” () of a computer gives an upper bound on the relative
error due to rounding in floating point arithmetic.
actual − approx
Recall, relative error is | |.
approx
Knowing a computer’s Machine epsilon and a matrix’s SVD can help us determine the numerical
rank of a matrix. Here’s How:
Determining the Numerical Rank of a Matrix: Suppose a computer has a Machine Epsilon,
and suppose matrix A has singular values σ1 ≥ σ2 ≥ ... ≥ σn . Let b = σ1 · · n where n is the
dimension of A and let k be the largest integer such that σk ≥ b. Then k is the numerical rank of
A.
79
4. Suppose A is 4 by 4 matrix with singular values σ1 = 2, σ2 = 1, σ3 = 10−1 and σ4 = 10−7
and we have a Machine Epsilon, = 10−5 . What is the numerical rank of A? What is the
rank of A?
In some circumstances you know there is noise, but you don’t know how much noise. So how do we
know which rank k approximation we should use to approximate our matrix? One method to help
is to plot the singular values of our matrix. If we look at our figure below (from our text When
Life is Linear ), notice for what value we have a steep drop-off. This drop-off tell us which rank k
approximation we should use.
5. From the chart above, how many singular values would you choose to use?
80
7.5 Markov Chain Application: Board Games
Consider the board game above from your textbook, When Life is Linear. Here are the rules: You
start on square 1 and you win when you reach square 9. On each turn, you roll a die. Rolling a 1
or 2 means you do no move and stay on your current square. Rolling 3 or 4 you move ahead one
square If you roll a 5 or 6, you move ahead 2 squares. You must climb the ladder if you are in
square 6 and slide down the snake if you land on square 4. Answer the following questions about
this board game.
7. Use Markov Chains to determine the minimum moves it could take to win the game.
1
0
0
0
Hint: Use x =
0
0 as the initial state (being at start) and you want to find the first x
k
0
0
0
0
state such that the 9th row of the vector is nonzero.
8. How many moves is it necessary for it to be 50% likely that someone has won?
81
9. Create your own version of the game Snakes and Ladders above, making sure you have at
least one snake (a space that brings you to a lower numbered space) and one ladder (a space
that brings you to a higher numbered space). Then find the transition matrix for your version
of the game. (Use the space below for your answer/work or another sheet of paper!)
10. If you are willing to provide feedback for this lab, please fill out the survey for our study at
the following link: http://bit.ly/linearalgebralabs2020
82
8 Extra Lab 8: Radiography and Tomography Part 4:
Reconstruction Without an Inverse6
8.1 Pre-Lab 8
Read the following pages and answer the Pre-Lab questions.
In this lab, we will consider the cases when the matrix representation of the radiographic transfor-
mation does not have an inverse. (Note: we say that T : V → W has an inverse T −1 : W → V if
T −1 T = IV , the identity mapping from V to V , and T T −1 = IW the identity mapping from W to
W . We say that T : V → W has a one-sided inverse7 , P : W → V if P ◦ T = IV .)
6
Radiography/Tomography c 2016 T. Asaki, C. Camfield, H. Moon, M. Snipes
7
More specifically, this is a left inverse of T .
83
Begin by considering the following theorem.
Idea Behind Proof: Hint: What type of matrix is T T T ... and use a result from our notes
A more formal way to prove this is as follows:
Proof. We can show that null(T T T ) = {0}, then because T T T is square we have that T T T is
invertible. Let x ∈ null(T T T ). We have
0 = xT 0 = xT T T T x = (T x)T (T x) = kT xk2
which implies T x = 0, that is, null(T T T ) = null(T ). Now, since rank(T ) = dim(V ), null(T ) = {0}
and null(T T T ) = {0}. Therefore T T T has linear independent columns and thus by the Invertible
Matrix Theorem has an inverse.
8
Note that since V and W are finite-dimensional spaces, we can fix bases for each, and then in those
coordinates, the transformation T can be represented by a matrix. T T is the transpose of this matrix
84
8.1.1 Pre-Lab 8 Questions: Inverting Radiographic Transformations
In this section, we will consider the following example: We are given a radiograph with 24 pixels
that was created by applying some radiographic transformation, T to an object with 16 voxels.
1. (Review Question) Give a scenario for a radiographic transformation T that fits the above
example. Don’t calculate a matrix T , rather give the following:
2. Suppose we know the radiograph b and we want to find the object x, where T x = b.
(a) What properties must the transformation T have so that the one-sided inverse of T
exists?
(b) When N ≤ M (as in the example above), what matrix properties must the matrix
representation of T have so that it has a one-sided inverse?
3. For ease of notation, we use the same notation for the matrix and the transformation, that
is, we call the matrix representation of T , T . Suppose, N ≤ M and a one-sided inverse, P of
T exists. This means that for all objects x with radiographs T x = b, we have x = P b. If T
were invertible, then P = T −1 . But, in the example above, we know that T is not invertible
(it is not even a square matrix!). Using the following steps, find the one-sided inverse of T .
85
(b) Provide a matrix A that has the properties you listed in 3a and such that the compo-
sition AT is invertible.
(c) Solve for x in the matrix equation AT x = Ab using the A you found, and provide a
representation of the one-sided inverse P .
4. Putting this all together now, state a necessary and sufficient condition for T to have a
one-sided inverse.
86
8.2 Lab 8: Application to a Small Example
Consider the following radiographic example.
• ScaleF ac = 1
• Number of views: a = 6
• View angles: θ1 = 0◦ , θ2 = 20◦ ,θ3 = 40◦ ,θ4 = 60◦ ,θ5 = 80◦ ,θ6 = 100◦ .
1. Use tomomap.m to compute T and verify that the one-sided inverse of T must exist. Note
that function tomomap returns a transformation matrix in sparse format. To use and view
as a full matrix array use the command T=full(T); after constructing T .
2. Compute the one-sided inverse P . Use P to find the object that created the following
radiograph vector (by copying and pasting into Octave or Matlab from the electronic copy
of this document in our class folder on the P: drive):
b=[0.00000
32.00000
32.00000
0.00000
1.97552
30.02448
30.02448
1.97552
2.71552
29.28448
29.28448
2.71552
2.47520
29.52480
29.52480
2.47520
1.17456
30.82544
30.82544
1.17456
1.17456
30.82544
30.82544
1.17456]
87
P= ; %insert your formula for P here!!
x= ; %insert what x is in terms of other quantities here!!
figure;
imagesc(reshape(x,a,b)); %change a and b to the dimensions of your object!
colormap(gray);
caxis([0 16]);
colorbar
Here are some notes about the commands in the code above:
1. Collect the necessary provided files and place them in your working Octave/Matlab directory.
2. Choose whether to create a new script file (“.m” file) for all of your commands or to work at
the Octave/Matlab prompt.
load Lab5Radiographs.mat
This line loads an array variable named B which is a 12960x362 array. Each column is a
radiograph corresponding to one horizontal slice of the human head. Each radiograph has
12960 total pixels spread across many views. The first 181 columns are noiseless radiographs
and the last 181 columns are corresponding radiographs with a small amount of noise added.
4. Use the familiar function tomomap.m to construct the transformation operator T correspond-
ing to the following scenario (which is the scenario under which the radiographic data was
obtained): n = 108, m = 108, ScaleF ac = 1, and 120 view angles: the first at 1◦ , the last at
179◦ , and the rest equally spaced in between (hint: use the linspace command).
88
5. Some Octave/Matlab functions do not work with sparse arrays (such as your T ). So, simply
just make T a full array with this command:
T=full(T);
6. It is tempting to compute the one-sided inverse P as found in 3c of the first part. However,
such a large matrix takes time to compute and much memory for storage. Instead we can
use a more efficient solver provided by Octave/Matlab. If we seek a solution to Lx = b, for
invertible matrix L, we find the unique solution by finding L−1 and then multiplying it by b.
Octave/Matlab does both operations together in an efficient way (by not actually computing
L−1 ) when we use the command x=L\b.
Let’s try this with the first radiograph in the matrix B. That is, we will reconstruct the slice
of the brain that produced the radiograph that is represented in the 50th column of B. We
want to solve the equation you found in 3c (recall the matrix you found to be A). Using the
A you found in 3c in the following commands
b=B(:,50);
x=(A*T)\(A*b);
you will find your first brain slice reconstruction. Now to view your reconstruction, use the
following commands
figure;
x=reshape(x,108,108);
imshow(x,[0,255]);
(The reshape command is necessary above because the result x is a (108 · 108) × 1 vector,
but we want the object to be 108 × 108 image.)
7. Notice also that x and b could be matrices, say X and B. In this case, each column of X is
the unique solution (reconstruction) for the corresponding column of B. Use these ideas to
reconstruct all 362 brain slices using a single Octave/Matlab command.
Use the variable name X. Make sure that X is an 11664x362 array. Now, the first 181
columns are reconstructions from noiseless data and the last 181 columns are reconstructions
from noisy data.
8. Run the script file ShowSlices.m which takes the variable X and plots example slice recon-
sructions. Open ShowSlices.m in an editor and observe the line
slices=[50 90 130];
You can choose to plot any three slices by changing the slice numbers. In the figure, the
left column of images are reconstructions from noiseless data, the right column of images are
reconstructions from the corresponding noisy data. IMPORTANT: Once you have computed
X you need only run ShowSlices.m to view different slices; running the other commands
described above is time consumming and unnecessary.
Print out a picture of your favorite set of 3 slices to turn in with your work from this lab.
89
Noisy Data and Reconstructions
Congratulations! You have just performed your first brain scan tomography. Using your new tool,
answer the following questions.
1. Are the reconstructions from the noiseless radiographs exact discrete representations of the
brain? Explain, using linear algebra concepts.
2. Find a method for determining the relative amount of noise in the noisy radiographs. It might
be useful to know that the noisy radiograph corresponding to the radiograph represented in
the 50th column of B is in the (181 + 50)th column of B. (Note: There are many ways you
can do this, be creative.) Is there a lot or a little noise added to the radiographs?
3. Are the reconstructions from the noisy radiographs exact representations of the brain?
4. Compare the degree of “noisiness” in the noisy radiographs to the degree of “noisiness” in
the corresponding reconstructions. Draw some conclusion about what this comparison tells
us about the practicality of this method for brain scan tomography.
90
9 Extra Lab 9: Heat Diffusion in Linear Algebra Lab
This lab talks about Heat Diffusion and 1-D Heat Warping and their relationships with Linear
Algebra9
We want to explore this application further and formulate our problem in a finite dimensional
vector space. We will use our knowledge of linear algebra to compute the heat state at any later
time as the heat diffuses.
9 c 2015-2018 T. Asaki, H. Moon, M. Snipes
91
9.1.2 Heat States in a (Vector) State Space
In the previous part of the discussion we modeled the heat along a bar by a continuous function
f , which we call the heat state of the bar. We will discretize such a heat state f by sampling the
temperature at m locations along the bar. If we space the m sampling locations equally, then for
L b−a
∆x = m+1 = m+1 , we can choose the sampling locations to be a + ∆x, a + 2∆x, . . . , a + m∆x. (We
will assume that the heat state is known (and fixed) at the endpoints so we don’t need to sample
there!) Then, the discretized heat state is the following vector u in Rm .
Notice that f (a) = f (b) = 0, where b = a + (m + 1)∆x. Also, if uj = f (x) for some x ∈ [a, b]
then uj+1 = f (x + ∆x) and uj−1 = f (x − ∆x). The figure below shows a continuous heat state
on the left and a heat state with sampling points marked on the right (although the initial and
final points on the heat state are marked in the figure, they are not part of the vector u). A note
about notation: in these notes we do not use special notation for vectors (such as bold typeface or
arrows).
To complete our vector space development (we need the set of heat states to form a vector space
so that we can use Linear Algebra in this setting), we must define heat state addition and scalar
multiplication.
92
2. We define vector addition in the usual componentwise fashion. Addition can result in changes
in both amplitude and period.
2. The rate of change of temperature at any location x is proportional to the second derivative
of the temperature with respect to position.
3. Temperature is changing fastest at sharp peaks or dips in temperature where the curvature
is large.
4. Regions where temperature is changing slowly are where |∂ 2 f (x)/∂x2 | is small. This occurs
under two different conditions:
(a) Where the temperature profile has nearly constant slope (no concavity).
(b) Near inflection points of the temperature profile.
5. The sign of the second derivative ensures that the heat state function does approach the zero
function.
93
9.1.4 The Discrete Heat Equation, in x
Because derivatives are linear, intuitively we believe that it should be possible to get a good discrete
approximation. So, we discretize the derivatives, using the definition of derivative
∂f f (x + h) − f (x) f (x) − f (x − h)
= lim = lim .
∂x h→0 h h→0 h
Notice that in a discrete setting, it is not possible for h → 0. The smallest h can be is ∆x. Let’s
use this to make the matrix representation for the second derivative operator, which we call D2 .
That is, D2 u approximates ∂ 2 f /∂x2 .
∂2f ∂ ∂f ∂ f (x+h)−f (x) ∂ f (x + ∆x) − f (x)
= = ∂x lim h ≈
∂x2 ∂x ∂x h→0 ∂x ∆x
" f (x+h)−f (x) f (x+∆x−h)−f (x−h) #
−
= lim ∆x ∆x
≈ f (x+∆x)−f (x)−f(∆x)
(x+∆x−∆x)+f (x−∆x)
2
h→0 h
1
≈ (∆x) 2 [f (x + ∆x) − 2f (x) + f (x − ∆x)]
Notice that we have used both a forward and backward difference definition of the derivative in order
to make our approximation symmetric. This helps us keep the later linear algebra manageable. In
our discretization, we have
∂ 2 uj 1
= (uj+1 − 2uj + uj−1 ).
∂x2 (∆x)2
1
which is (∆x)2 (next heat state −2·(current heat state)+previous heat state). Which makes sense
the current heat state should depend on the heat states surrounding it.
Example 9.1. Write the matrix representation for the second derivative operator, D2 with respect
1 10
to the standard basis using D2 (uj ) = (∆x) 2 (uj+1 − 2uj + uj−1 ) for {u1 , u2 , ..., u6 }
−2
1
0
1
Answer: Since D2 (u1 ) = [ (∆x)2 (u2 − 2u1 + 0)]U =
1
(∆x)2
·
0
0
0
1
−2
0
1
D2 (u2 ) = [ (∆x)2 (u3 − 2u2 + u1 )]U =
1
(∆x)2
·
0
0
0
10
Note: This means that if we want to take a discrete second derivative, we do the matrix multiply D2 u.
94
0
1
−2
1
D2 (u3 ) = [ (∆x)2 (u4 − 2u3 + u2 )]U =
1
(∆x)2
·
0
0
0
Etc.
−2 1 0 0 0 0
1 −2 1 0 0 0
1 0 1 −2 1 0 0
.
D2 =
(∆x)2
0 0 1 −2 1 0
0 0 0 1 −2 1
0 0 0 0 1 −2
So,
∆t ∆t
u(t + ∆t) = u(t) + D2 u(t) = I+ D2 u(t).
(∆x)2 (∆x)2
∆t
Let E be defined as the matrix I + (∆x) 2 D2 . Then we have u(t + ∆t) = Eu(t). That is the next
∆t ∆t
Example 9.2. Compose the matrix representation of E. Note E = In + (∆x)2 D2 and let δ = (∆x)2
(which is a constant)
1 0 0 0 −2 1 0 0 1 − 2δ δ 0 0
0 1 0 0 ... 1 −2 1 0 . . . δ 1 − 2δ δ 0 ...
E= 0 0 1 0 + δ ∗ 0 1 −2 1 = 0 δ 1 − 2δ δ
.. .. .. .. .. ..
. . . . . .
95
∆t 1
Technical Detail: We need 0 < δ ≡ (∆x) 2 ≤ 4 for computational stability, though the proof is
beyond the scope of this module. ∆x is fixed so we need to take small enough time steps ∆t to get
this inequality. Hence as we let ∆x → 0, we are also implicitly forcing ∆t → 0.
1 − 2δ δ 0 0
δ 1 − 2δ δ 0 ...
So u(t + ∆t) = E · u(t) = 0 δ 1 − 2δ δ · u(t)
.. ..
. .
Consider the meaning of the row and column representations of E.
3. How can we interpret the fact that all but the first and last columns (and rows) sum to unity
(1)?
Answer: Based on the above discussion, we see that this guarantees that no heat is lost
from the system except at the end points. Heat is redistributed (diffused) not lost.
Example 9.3. We found the matrix representation of the heat diffusion operator to be
1 − 2δ δ 0 0
δ 1 − 2δ δ 0 ...
E= 0 δ 1 − 2δ δ .
.. ..
. .
We see that if we are want to find the kth heat state, u(k∆t) in the heat diffusion, we need to use
u(k∆t) = E k u(0),
96
where u(0) is the initial heat state. Let’s explore what happens when we do these calculations.
1. What is the equation for the heat state 2 steps in the future? 1000 time steps in the future?
3. Does it look like raising E to higher and higher powers is an easy way to find the heat state
at some time far in the future (for example, 1000 time steps away)?
4. Does it look like multiplying over and over by the matrix E is an easy way to find the heat
state at some time far in the future?
5. If you had to perform this kind of operation, what characteristics would you prefer a diffusion
operator to have?
97
9.1.7 In-Class PreLab Demonstrations Heat Diffusion
Recall the properties of heat diffusion:
1. Places where the temperature is higher than the surrounding area will cool.
2. Places where the temperature is cooler than the surrounding area will warm.
3. As the heat diffuses, sharpest temperature differences (higher frequency wiggles) disappear
first.
4. The long-term behavior is that temperatures smooth out approaching 0 heat everywhere.
Demo 1: We will now show an example diffusion of a heat state (using HeatEqnClassDemos.m).
In Matlab or Octave, type HeatEqnClassDemos(1)
Note: There is a 10 second pause that allows the class to see the original heat signature. We can
use this time to prepare to check the conjectures made above. This demo completes 500 iterations.
We should watch for more sharply curving (actually called high frequency) areas to diffuse away
faster than low frequency areas. Another way to say this is that small scale features disappear
sooner than larger scale features.
Demo 2: Now let’s look at a demo which is a better match for the scenario of diffusion welding:
HeatEqnClassDemos(2)
Question: What happens if a heat source (or several) are placed in a room: how will the heat
diffuse throughout the room?
The idea of diffusion can be used to morph one image into another. The video USA.mp4 uses
diffusion to transition from image to image.
The ideas behind the movie creation are explored in the 1-dimensional setting in the following Lab.
98
9.2 Lab 9: Morphing 1-D heat signatures
Suppose that we start with two heat signatures, v and w, and we want to heat evolve one into the
other. One way to do this is to heat evolve the difference between the two heat signatures v − w.
In the following activity we will explore this process with the heat signatures v and w pictured
below. (In the figure, v is the upper function in purple and w is the lower function in blue.)
2. Use your intuition about heat diffusion to sketch some (at least 3) future heat signatures that
might arise from evolving v − w for different lengths of time. (Add these to your sketch from
the previous part). We can give names to the functions you drew. Define a family of heat
signatures xt , where x0 = v − w is the initial heat signature, and xt is the heat signature
after time t. (The heat signatures in your drawings that occur earlier in the evolution are
associated with lower values of t than the ones that occur later.)
3. Add a sketch of the limiting heat signature, x∞ , that results from evolving v − w. We can
define the heat signature at time t to be xt , creating a family of heat signatures for t ≥ 0
where
4. Now let’s think about how the sketches you’ve made from the previous part might help you
to morph the function v into the function w. Consider the related family of heat signatures,
where for t ≥ 0, zt := w + xt . On a new set of axes, sketch the graphs of zt that correspond
to the xt you sketched above. (Also include x0 and x∞ .)
5. Fill in the blanks: the family zt for t ≥ 0 morphs the heat signature
into the heat signature .
6. The family of functions zt shows a heat signature morphing into another heat signature.
What do you notice about this morphing? In particular, what types of features disappear
and appear?
99
7. Another method for morphing heat signature v into heat signature w is to first diffuse v and
then follow this with the inverse of the diffusion of w. How is this different from what we
obtained above by diffusing the signature v − w ? (You may produce sketches of the heat
evolutions of v and w to support your discussion.)
Morphing Images
We now consider the task of morphing a 2-dimensional black and white image into another image,
like you saw in the demo11 .
Such an image can be thought of as consisting of pixels in a rectangular array with intensity values
assigned to each pixel: white pixels have high intensity (heat) and black pixels have low intensity
(heat). As in the one-dimensional case, we will assume the boundary intensities are zero. Boundary
pixels are those on the border of the rectangle.
The principles behind heat diffusion in two dimensions are similar to those we have been discussing
in one dimension. In particular,
• Places where the temperature is higher than the surrounding area will cool.
• Places where the temperature is cooler than the surrounding area will warm.
• The long-term behavior is that temperatures smooth out approaching 0 heat everywhere.
Hence if we take an image and heat diffuse it, the final heat state of the image will be the blank
(zero) image. We define a morphing between image V and image W as in the one-dimensional case
above: by diffusing the difference V − W and considering the associated family Xt as before.
11
Recall that the demo actually morphed color images; this was accomplished by morphing the red, green,
and blue components of the image separately and then combining them.
100