0% found this document useful (0 votes)
60 views100 pages

Linear Algebra Lab Packet 2020

This document outlines the contents and structure of a series of labs for a Math 307: Applied Linear Algebra course created by Professors Amanda Harsy and Michael Smith. The labs cover topics including matrix algebra, computer graphics, radiography, tomography, translation/rotation matrices, Markov chains, and heat diffusion. Each lab module includes pre-lab reading assignments and questions, in-class activities, and post-lab questions. The overarching goals are to apply linear algebra concepts to real-world problems and connect mathematical theory to practical applications through an experiential learning approach.

Uploaded by

deepakbhatr
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)
60 views100 pages

Linear Algebra Lab Packet 2020

This document outlines the contents and structure of a series of labs for a Math 307: Applied Linear Algebra course created by Professors Amanda Harsy and Michael Smith. The labs cover topics including matrix algebra, computer graphics, radiography, tomography, translation/rotation matrices, Markov chains, and heat diffusion. Each lab module includes pre-lab reading assignments and questions, in-class activities, and post-lab questions. The overarching goals are to apply linear algebra concepts to real-world problems and connect mathematical theory to practical applications through an experiential learning approach.

Uploaded by

deepakbhatr
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/ 100

Math 307: Applied Linear Algebra Labs

Created by: Professors Amanda Harsy and Michael Smith


January 4, 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

2 Lab 2: Radiography and Tomography Part 1 15


2.1 Pre- Lab 2 (Rad/Tom Lab Part 1 Introduction) . . . . . . . . . . . . . . . . 15
2.2 In-Class: Introduction to Radiography and Tomography . . . . . . . . . . . 16
2.3 Lab 2: Radiography and Tomography: Part 1 . . . . . . . . . . . . . . . . 19

3 Lab 3: March Mathness: Using Linear Algebra for Predictive Modeling 23


3.1 Pre-Lab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.1.1 Directed Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.1.2 The Colley Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.2 Lab 3: In class portion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.2.1 The Massey System of Ranking . . . . . . . . . . . . . . . . . . . . . 27
3.2.2 Adding Weights to Colley and Massey Systems . . . . . . . . . . . . 29
3.2.3 Extra Examples of Massey and Colley . . . . . . . . . . . . . . . . . 32

4 Lab 4: Radiography and Tomography Part 2 37


4.1 Pre-Lab 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
4.1.1 Goals from the Reading Assignment: . . . . . . . . . . . . . . . . . . 37
4.1.2 Questions from the Reading Assignment: . . . . . . . . . . . . . . . . 37
4.1.3 Summary of Terminology from the Reading Assignment: . . . . . . . 48
4.2 Lab 4: Radiography and Tomography: Part 2 . . . . . . . . . . . . . . . . . 49

5 Lab 5: Translation and Rotation Matrices 59


5.1 Pre-Lab 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
5.2 Lab 5 In-Class Portion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
5.3 Bonus Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

6 Lab 6: Radiography and Tomography Lab Part 3 67


6.1 Pre-Lab 6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
6.1.1 Pre-Lab 6 Questions: . . . . . . . . . . . . . . . . . . . . . . . . . . . 68
6.1.2 In-Class Section of the Pre-Lab: . . . . . . . . . . . . . . . . . . . . . 71
6.2 Lab 6 Questions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74

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

8 Extra Lab 8: Radiography and Tomography Part 4: 83


8.1 Pre-Lab 8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
8.1.1 Pre-Lab 8 Questions: Inverting Radiographic Transformations . . . . 85
8.2 Lab 8: Application to a Small Example . . . . . . . . . . . . . . . . . . . . . 87

9 Extra Lab 9: Heat Diffusion in Linear Algebra Lab 91


9.1 Pre-Lab 9: Motivating Application for Eigenvalues and Eigenvectors . . . . . 91
9.1.1 Review of Heat States in a (Vector) State Space . . . . . . . . . . . . 91
9.1.2 Heat States in a (Vector) State Space . . . . . . . . . . . . . . . . . . 92
9.1.3 The Heat Equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
9.1.4 The Discrete Heat Equation, in x . . . . . . . . . . . . . . . . . . . . 94
9.1.5 The Discrete Heat Equation, in t . . . . . . . . . . . . . . . . . . . . 95
9.1.6 Heat State Evolution . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
9.1.7 In-Class PreLab Demonstrations Heat Diffusion . . . . . . . . . . . . 98
9.2 Lab 9: Morphing 1-D heat signatures . . . . . . . . . . . . . . . . . . . . . . 99

Pre-Lab Assignments
• Lab 1: No pre-lab assignment.

• Lab 2: Read page 13 before lab.

• 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 4: Read The Transmission Radiograph and Tomography (A Simplified Overview)


and answer the questions on first 2 pages of pre-lab. Turn these in with Lab 4 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.

• Lab 7: Complete the pre-reading in Section 7.1.

• Extra Lab 8: Read and answer questions from Section 8.1.

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.

[3] James E Salzman and JB Ruhl. Who’s number one? 2009.

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

Definition 1.1. An m × n matrix is a rectangular ordered arrangement (an array) of


numbers with m rows and n columns.

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?

1.1 Connection to Graphics


As we saw in Lab 1, grayscale images are stored in an ordered array or matrix. Consider
 
78 92 59 26
166 206 26 48 
A=  74
.
138 165 3 
66 151 250 214

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

of 78. The matrix A corresponds to the image:


We can use scalar multiplication to lighten or dim an image. Consider the grayscale image

of the Mona Lisa.

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

G = −M + B which will give us:


 
78 92 59 26
166 206 26 48 
2. If we wanted to invert the matrix for A =  
 74 138 165 3  , what would be our
66 151 250 214
resulting matrix?

1.2 Introduction to Octave


We are now going to introduce a multi-paradigm numerical computing environment and
proprietary programming language called MatLab which will be very useful in this course.
MatLab can be used in our computer labs, but a free version of MatLab, called Octave, can
be used online.
Instructions for using octave-online.net
• Open octave-online.net in a web browser. Close (or read and close) the introduction
splash window.
• Click the three bars in the upper right of the screen and sign in.
• 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.

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

redSlope = 1; greenSlope = -.75; blueSlope = -.50;


redIntercept = -80; greenIntercept = 150; blueIntercept = 200;

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.

5. Bonus Question: From The Matrix: Neo: “What is the Matrix?”


a) Trinity: “The answer is out there,... it’s looking for you, and it will find you if you want
it to.”
b) Morpheus: “The Matrix is everywhere. It is all around us. Even now, in this very room...
It is the world that has been pulled over your eyes to blind you from the truth.”
c) Trinity: “The Matrix isn’t real.”
d) Morpheus: “The Matrix is a system, Neo. That system is our enemy.”
e) Morpheus: “Control. The Matrix is a computer-generated dream world built to keep us
under control in order to change a human being into this.”
f) Morpheus:“Unfortunately, no one can be told what the Matrix is. You have to see it for
yourself.”
g) None of the above, instead it is .... (fill in your answer below)

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

For each of the exercises below, use the matrices


 
1 1 0
   1 −1 2   
1 1 1 0   0 2 3 4
 1 2 0 
P =  2 1 3 −1  , Q =   3
,
 R =  1 −1 −3 −1  ,
 0 0 
2 2 0 0  2 −1 −2 0 1
2 2 
1 0 −1
 
0 0 −1 0 2 1
and S =  −3 −1 −2 1 2 0 
2 −1 0 1 2 −1

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?

(f) What addition property do you notice about matrix addition?

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

Bonus Questions on next page!

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

(b) for a = .25

(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

Figure 1: Examples of image arrays. Numbers indicate example pixel ordering.

Addition: We can add 2 images together to get another image!

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(1) shows a sequence of horizontal slices through a brain. The first


frame is somewhere near the level of the nose and each subsequent frame (181 in all) is higher
than the previous one. At the end of the “movie,” you will see a rectangular object which is
a stabilizer for keeping the subject’s head from moving during the procedure. These slices
are examples of desired images of the brain one might want to use to identify or evaluate
abnormalities. Gray values are proportional to density: bone shows up bright white with
soft tissue exhibiting various shades of gray. We cannot physically slice a person’s head to
get such information. What we can do is take images such as what happens in a CAT scan
and use these to produce the slices.

RadTomExamples(2) shows a sequence of 30 representative CAT scan images that are


actually taken in such a radiographic exam. Each view is taken from a different angle around
the head in increments of 6 degrees. Each view is perpendicular to the horizontal slices that
we just viewed. These radiographs show grayscale values that contain some Poisson instru-
mentation noise. Longer exposures have less relative noise as long as the detector array can
accurately handle the x-ray intensity.

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?

RadTomExamples(4) shows the series of brain slice reconstructions using a relatively


simple left-inverse method (this is developed and implemented by students in Lab 5). The
reconstruction uses 120 low noise (high exposure) radiographs from unique angles around
the head. Notice that the reconstructions are noisier than the radiographs. This noise am-
plification effect is typical in inverse problems with noisy data.

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

Question: What are the goals of a researcher in this mathematical field?


RadTomExamples(7) shows a comparison of three reconstructions methods: (top) noise-
sensitive pseudo-inverse on hundreds of low-noise radiographs, (middle) left-inverse on 120
low-noise radiographs, (bottom) noise-sensitive pseudo-inverse on 30 low-noise radiographs.

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.

RadTomExamples(9) shows a comparison of all four reconstruction methods: (top) noise-


sensitive pseudo-inverse on hundreds of low-noise radiographs, (second) left-inverse on 120
low-noise radiographs, (third) noise-sensitive pseudo-inverse on 30 low-noise radiographs,
(bottom) noise-sensitive pseudo-inverse on 30 low-noise radiographs with transformation
null-space enhancements. In the course of the parts of the Radiography and Tomography
Labs, we will learn how to perform each of these types of brain reconstructions. Although
we will not get to the later parts of the lab, we want to show the the results of these
reconstructions in order to demonstrate that more sophisticated reconstructions involving
further study of linear algebra are available to deal with noise and sparser data.

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.

Image A Image B Image C

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.

Exercise 5: Please give some thoughts on the following questions.

(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

Instructions for using octave-online.net


1. Open octave-online.net in a web browser. Close (or read and close) the introduction
splash window.

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.

4. Now you are ready to complete the assignment!

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.

3.1.1 Directed Graphs


Before we discuss two different ranking methods, first we will talk about a way to organize
sports data. Suppose we have 4 teams, Team A, B, C, & D. Team A beats B and D, C
beats D and B, and Team D beats team B. You can represent this situation using a directed
graph with the teams making up the vertices of the graph. This graph is sometimes called
the “The Poor Sportsmanship Graph”.

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

This gives us a nice symmetric matrix system, Cr = b:


     
4 −1 −1 rA 1
−1 5 −2 · rB  = 0.5 (6)
−1 −2 5 rC 1.5
   
rA 0.5
Solving this system gives us rB  = 0.42857. We order the team rankings by the value
rC 0.57143
of the ratings with the largest rating corresponding with the top ranked team. Putting the
ratings in order from largest to smallest, we get the following ranking: Team C first, Team
A second, and Team B third.

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?

3.2.1 The Massey System of Ranking


Suppose we want to use a system of rating that incorporates the scores of the games.On the
other hand, Kenneth Massey’s method of sports rating creates a system of equations which
is based on the score of the games played. Massey originally created this method for ranking
college football teams [3, 2]. Using the Massey Method, for each game, the difference in the
ratings correlates to the point differential [2]. This is represented as a system: ri − rj = bk
where ri is the rating for team i and rj is the rating for team j and bk is the score differential
for game k.

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

Which will give us the following matrix system, Xr = b:


   
1 −1 0   7
−1 0 rA


1    1 

 0 −1 1  · rB =  1  (7)
rC
0 1 −1 10
Note that each row of our system of equations representing a particular game from the data
set. Our columns represent the different teams being ranked. This usually means in practice
that our system has more rows than columns.
7. Problem: This system is inconsistent. That is, there are solutions. What
method can we use to “approximate” a solution?

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

We then solve this new weighted system


  following
 the
 same methods as an unweighted
rA 2.00
Massey model. Solving this gives us: rB  =  3.102  Which gives us the ranking: Team
rC −5.102
B, Team A, and Team C.

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.

Setting up the Colley system then gives us:


   
4.5 −2.5 0 2.25
−2.5 5.5 −1 r = 0.25 (14)
0 −1 3 0.5
   
rA 0.745
Solving this system gives us rB  = 0.441 which gives us the ranking Team A, Team B,
rC 0.314
and Team C.
Note: There are more sample problems in Section 3.2.3.

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.

Solution: First we set up the following system of equations:

rA − rB = 7
rC − rA = 1
rC − rB = 1
rB − rC = 10

Which will give us the following matrix system, Xr = b:


   
1 −1 0   7
−1 0 rA
 1    1
 

 0 −1 1  · rB =  1  (15)
rC
0 1 −1 10
Note that each row of our system of equations representing a particular game from the data set.
Our columns represent the different teams being ranked. Unfortunately, this system, Xr = b will
usually be inconsistent (rarely does a team beat a team twice by the same score and note in this
example that is true). Therefore the Massey Method uses least squares to solve its system. To find
a least squares solution we multiply both sides of our original equation Xr = b, by the transpose
of X. The transpose matrix, denoted X T , is a matrix whose rows are the columns of the original
matrix X. Thus we now have the system X T Xr = X T b:
   
  1 −1 0     7
1 −1 0 0 −1 0  rA 1 −1 0 0 1
−1 0 −1 1  ·  1       
 0 −1 1  · rB = −1 0 −1 1 ·  1  (16)
0 1 1 −1 rC 0 1 1 −1
0 1 −1 10
     
2 −1 −1 rA 6
−1 3 −2 · rB  =  2  (17)
−1 −2 3 rC −8
Remember sometimes there are multiple least squares solutions. As is the case for this example.
To fix this, Massey needed to force his system to have one unique solution. He did this by replacing
one of the rows with an equation which is not in the span of the other rows of the system (that is,
not a linear combination of the other rows). He could replace any row, but for consistency, Massey
Xm
replaces the last row of the system with ri = 0. This ultimately means that the sum of the
i=1

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

Solving this system gives us    


rA 2
rB  =  0 
rC −2
We order the teams ranking by the value of the ratings with the largest rating corresponding with
the top ranked team. Thus in the example above, we would rank team A first, Team B second, and
Team C third. Note that if we ranked the teams by win percentage, we would have the ranking
Team C, Team A, and Team B.

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

Completing the matrix multiplication gives us:


   
1.25 −1.25 0 7.5
−1.25 1.5 −0.25 r =  −5  (28)
0 −0.25 0.25 −2.5
Finally we replace the last row of M̃ T M̃ with 1’s and the last row of M̃ T b̃ with 0 to get:
   
1.25 −1.25 0 7.5
−1.25 1.5 −0.25 r = −5 (29)
1 1 1 0
 
7.5
Solving this gives us r =  1.3  which gives us the ranking: A, B, C.
−8.6

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.

Solution: We first set up the weighted Colley system:


1 − .5
(2 + 1.5)rA = 1 + + rB + 0.5rC
2
3−2
(2 + 5)rB = 1 + + rA + 4rC
2
1.5 − 3
(2 + 4.5)rC = 1 + + 0.5rA + 4rB
2
(Note: Team A has played a total of 1 early game and 1 mid game which means a total of 1.5
weighted games (1 · 0.5 + 1 · 1) and has a total of 1 weighted wins and 0.5 weighted losses. Team B
has played two mid games and 1 late game which means Team B has played a total of 5 weighted
games (1 · 3 + 2 · 1) and has 3 weighted wins and 2 weighted losses. etc.) Rearranging the system
gives us:
5
3.5rA − rB − 0.5rC =
4
3
−rA + 7rB − 4rC =
2
1
−0.5rA − 4rB + 6.5rC =
4
Solving this system gives us the following matrix system, Cr = b:
    5
3.5 −1 −0.5 rA 4
 −1 7 −4  · rB  =  32  (31)
1
−0.5 −4 6.5 rC 4
   
rA 0.56593
Solving this system gives us rB  = 0.52747. Which gives us the ranking Team A, Team B,
rC 0.40659
then Team C. Note that this is different from what we got when we did the basic unweighted Colley
Method in Example 3.9.

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.

4.1.1 Goals from the Reading Assignment:


• To understand a unified and simplified physical model of taking an x-ray radiograph of an
object.

• To recognize and appreciate that, sometimes, complex phenomena can be reasonably modeled
with straightforward mathematics.

• To recognize and appreciate that mathematical assumptions should be backed by physical


reality in order to preserve model integrity. This is justification!

• To be exposed to the notation used in the Lab 2.

• To understand the matrix equation representation of the radiographic process.

4.1.2 Questions from the Reading Assignment:


1. Given Tkj = 0.42, what does this value mean?

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

Transmission Radiography and Tomography


A Simplified Overview

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.

• Multiple-view X-ray radiography is realized in computerized axial tomography (CAT)


scans used to provide 3D images of body tissues.

• Neutron and X-ray imaging is used in industry to quantify manufactured part assem-
blies or defects which cannot be visually inspected.

Transmission Radiography is the process of measuring and recording changes in a high-


energy particle beam (X-rays, protons, neutrons, etc.) resulting from passage through an
object of interest.

Tomography is the process of inferring properties of an unknown object by interpreting


radiographs of the object.

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

Figure 1: Typical radiographic experiment.

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

The Incident X-ray Beam


We begin with an x-ray beam in which the x-ray photons all travel parallel to each other in
the beam direction, which we take to be the positive x-direction. Additionally we assume
that the beam is of short time duration, the photons being clustered in a short pulse instead
of being continuously produced. A beam with these geometric characteristics is usually
not directly achievable through typical x-ray sources (see supplementary material for some
discussion on x-ray sources). However, such a beam can be approximated readily through
so-called collimation techniques which physically limit the incident x-rays to a subset that
compose a planar (neither convergent nor divergent) beam.
While not entirely necessary for the present formulation, we consider a monochromatic
x-ray source. This means that every x-ray photon produced by the source has exactly the
same “color.” The term “monochromatic” comes from the visible light analog in which,
for example, a laser pointer may produce photons of only one color, red. The energy of a
single photon is proportional to its frequency ν, or inversely proportional to its wavelength
λ. The frequency, or wavelength, determine the color, in exact analogy with visible light.
In particular, the energy of a single photon is hν where the constant of proportionality h is
known as Planck’s constant.
The intensity (or brightness), E(x, y, z), of
40a beam is proportional to the photon density.
The intensity of the beam just as it enters the region of interest at x = 0 is assumed to be

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.

X-Ray Beam Attenuation


As the beam traverses the region of interest, from x = 0 to x = Dx (see Figure 2), the
intensity changes as a result of interactions with matter. In particular, a transmitted (resul-
tant) intensity E(Dx , y, z) exits the far side of the region of interest. We will see that under
reasonable assumptions this transmitted intensity is also planar but is reduced in magni-
tude. This process of intensity reduction is called attenuation. It is our goal in this section
to model the attenuation process.
X-ray attenuation is a complex process that is a combination of several physical mecha-
nisms (outlined in the supplementary material) describing both scattering and absorption of
x-rays. We will consider only Compton scattering which is the dominant process for typical
medical x-ray radiography. In this case, attenuation is almost entirely a function of photon
energy and material mass density. As we are considering monochromatic (monoenergetic)
photons, attenuation is modeled as a function of mass density only.
Consider the beam of initial intensity E(0, y, z) passing through the region of interest, at
fixed y and z. The relative intensity change in an infinitesimal distance from x to x + dx is
proportional to the mass density ρ(x, y, z) and is given by

dE(x, y, z) = E(x + dx, y, z) − E(x, y, z) = −µρ(x, y, z)E(x, y, z)dx


where µ is a factor that is nearly constant for many materials of interest. We also assume
that any scattered photons exit the region of interest without further interaction. This is
the so-called single-scatter approximation which dictates that the intensity remains planar
for all x.
Integrating over the path from x = 0 where the initial beam intensity is E(0, y, z) to
x = Dx where the beam intensity is E(Dx , y, z) yields

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.

Radiographic Energy Detection


The transmitted intensity E(Dx , y, z) continues to travel on to a detector (e.g. film) which
records the total detected energy in each of m detector bins. The detected energy in any bin
is the intensity integrated over the bin cross-sectional area. Let pk be the number of x-ray
photons collected at detector bin k. pk is then the collected intensity integrated over the bin
area and divided by the photon energy.
ZZ  R 
1 −µ 0Dx ρ(x,y,z)dx
pk = E(0, y, z) e dydz.
hν (bin k)

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 ,

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

total mass fraction of voxel j total mass


along in beam path k in voxel j
beam path k

Figure 3: Object space and radiograph space discretization.

The Radiographic Transformation Operator


We consider a region of interest subdivided into N cubic voxels (three-dimensional pixels).
Let xj be the mass in object voxel j and Tkj the fraction of voxel j in beam path k (see
Figure 3). (Note that this is a different context, in particular, xj is *not* related to the
direction that the x-ray beams are traveling!) Then the mass along beam path k is
N
X
sk = Tkj xj ,
j=1

and the expected photon count at radiograph pixel k, pk , is given by


1 PN
pk = p0k e− α 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.

Multiple Views and Axial Tomography


Thus far, we have a model that can be used to compute a single radiograph of the region
of interest. In many applications it is beneficial to obtain several or many different views of
this region. In some industrial applications, the region of interest can be rotated within the
radiographic apparatus, with radiographs obtained at various rotation angles. In medical
applications the radiographic apparatus is rotated about the region of interest (including
the subject!). In this latter case, the voxelization remains fixed and the coordinate system
rotates. For each of a view angles the new m pixel locations require calculation of new mass
projections Tkj . The full multiple-view operator contains mass projections onto all M = a·m
pixel locations. Thus, for multiple-view radiography: x is still a vector in RN , but b is a
vector in RM and T is a matrix operator in MM ×N (R).
Finally, we make the distinction between the general scenario and axial tomography
(CAT scans). In principle, we could obtain radiographs of the region of interest from any
direction (above, below, left, right, front, back, etc.). However, in axial tomography the
physical limitations of the apparatus and subject placement dictate that views from some
directions are not practical. The simplest scenario is to obtain multiple views by rotating
the apparatus about a fixed direction perpendicular to the beam direction. This is why CAT
machines have a donut or tube shaped appearance within which the apparatus is rotated.
The central table allows the subject to rest along the rotation axis and the beam can pass
through the subject along trajectories.
This axial setup also simplifies the projection operator. If we consider the `th slice of
the region of interest, described by an n × n arrray of N voxels, the mass projections of
44
this slice will only occur in the `th row of pixels in each radiographic view see Figure 4.

6
DRAFT: Radiography/Tomography c 2016 T. Asaki, C. Camfield, H. Moon, M. Snipes

As a result, 3D reconsructions can be obtained by a series of independent 2D reconstructed


slices. For example, the brown slice of the spherical object (represented in RN ) is related to
the collection of brown rows of the radiographs (represented in RM ) through the projection
operator T ∈ MM ×N (R). The black slice and black rows are related through the same
projection operator.

Model Summary
The list below gathers the various mathematical quantities of interest.

• N is the number of object voxels.

• M is the number of radiograph pixels.

• x ∈ RN is the material mass in each object voxel.

• b ∈ RM is the mass projection onto each radiograph pixel.

• p ∈ RM is the photon count recorded at each radiograph pixel.

• p0 ∈ RM is the incident photon count possible for each radiograph pixel.

• T ∈ MN ×M (R) is voxel volume projection operator. Tij is the fractional volume of


voxel j which projects orthogonally onto pixel i.
 
• b = −α ln pp0 .

• b = T x is the (mass projection) radiographic transformation.

The description of images (objects and radiographs) as vectors in RN and RM is compu-


tationally useful and more familiar than a vector spaces of images. One should keep in
mind that this is a particular representation for images which is useful as a tool but is
not geometrically descriptive. The price we pay for this convenience is that we no longer
have the geometry of the radiographic setup (pixelization and voxelization) encoded in the
representation.
A vector in R3 , say (1, 2, 5), is a point in a three-dimensional space with coordinates
described relative to three orthogonal axes. We can actually locate this point and plot it.
An image represented in R3 , say (1, 2, 5), is not a point in this space. Without further
information about the vector space of which it is a member, we cannot draw this image. The
use of R3 allows us to perform scalar multiplication and vector addition on images because
these operations are equivalently defined on R3 .

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.

• Monochromaticity. Laboratory sources generate x-rays with a wide range of ener-


gies as a continuous spectrum. We say that such x-ray beams are polychromatic.
One method of approximating a monochromatic beam is to precondition the beam
by having the x-rays pass through a uniform material prior to reaching the region of
interest. This process preferentially attenuates the lower energy photons, leaving only
the highest energy photons. This process is known as beam-hardening. The result is
a polychromatic beam with a narrower range of energies. We can consider the beam
to be approximately monochromatic, especially if the attenuation coefficient(s) of the
material, µ, is not a strong function of photon energy.

• Geometric Beam Characteristics. Laboratory sources do not naturally generate


planar x-ray beams. It is more characteristic to have an approximate point source
with an intensity pattern that is strongly directionally dependent. Approximate planar
beams with relatively uniform intensity E(0, y, x) can be achieved by selective beam
shielding and separation of source and region of interest. In practice, it is common to
use the known point source or line source characteristics instead of assuming a planar
beam. The model described here is unchanged except for the computation of T itself.

• Secondary Radiation. Our model uses a single-scatter approximation in which if a


photon undergoes a Compton scatter, it is removed from the analysis. In fact, x-rays
can experience multiple scatter events as they traverse the region of interest or other
incidental matter (such as the supporting machinery). The problematic photons are
those that scatter one or more times and reach the detector. This important secondary
effect is often approximated by more advanced models.

• Energy-Dependent Attenuation. The attenuation coefficient µ, which we have


taked to be constant, is not only somewhat material dependent but is also beam energy
dependent. If the beam is truly monochromatic this is not a problem. However, for
a polychromatic beam the transmitted total energy will depend on the distribution of
mass along a path, not just the total mass.

• Other Attenuation Mechanisms. We have included only Compton scattering in the


model. Four other mechanisms (outlined in the supplementary material) contribute to
the attenuation. While Compton scattering is the dominant contributor, photoelectric
scattering will have some effect. It becomes important at the lower energies of interest
and for materials of relatively high atomic number – such as calcium which is concen-
trated in bone. The major effect of ignoring photoelectric scattering is quantitative
mass uncertainty.
46

8
DRAFT: Radiography/Tomography c 2016 T. Asaki, C. Camfield, H. Moon, M. Snipes

• There are a number of Detector-Related Effects which affect radiograph accuracy.


Energy detection efficiency can be a function of beam intensity, photon energy and
even pixel location. Detectors are subject to point-spread effects in which even an
infinitesimally narrow beam results in a finitely narrow detection spot. These types of
effects are usually well-understood, documented and can be corrected for in the data.
Detection is also prone to noise from secondary radiation, background radiation, or
simply manufacturing variances.

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

Several physical processes contribute to absorption and scattering of individual photons


as they pass through matter. Collectively, these processes alter the geometry and intensity
of a beam of such photons. What follows is a brief description of each.
• The Photoelectric Effect is the absorption of an x-ray photon by an atom accompa-
nied by the ejection of an outer-shell electron. This ionized atom then re-absorbs an
electron and emits an x-ray of energy characteristic of the atom. The daughter x-ray
is a low-energy photon which is quickly re-absorbed and is effectively removed from
the x-ray beam. Photoelectric absorption is the dominant process for photon energies
below about 100keV and when interacting with materials of high atomic number.
• Rayleigh Scattering is the process of a photon interacting with an atom without
energy loss. The process is similar to the collision of two billiard balls. Rayleigh
scattering is never the dominant mechanism, at any energy.
• Compton Scattering occurs when an x-ray photon interacts with an electron imparting
some energy to the electron. Both electron and photon are emitted and the photon
undrgoes a directional change or scatter. Compton Scattering is the dominant process
for soft tissue at photon energies between about 100keV through about 8MeV.
• Pair Production is the process in which a photon is absorbed producing a positron-
electron pair. The positron quickly decays into two 510keV x-ray photons. Pari produc-
tion is only significant for photon energies of several MeV or more.
• Photodisintegration can occur for photons of very high energy. Photodisintegration
is the process of absorption of the photon by an atomic nucleus and the subsequent
ejection of a nuclear particle. 47

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

Transmission Radiography is the process of measuring and recording changes in a high-energy


particle beam (X-rays, protons, neutrons, etc.) resulting from passage through an object of interest.

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.

Radiographic Scenarios and Notation


A single-view radiographic setup consists of an area of interest where the object will be placed, and
a single screen onto which the radiograph will be recorded. A multiple-view radiographic setup
consists of a single area of interest experimentally designed so that radiographs of this area can be
recorded for different locations about the object.
The geometry of radiographic scenarios is illustrated in figures 1 and 2. The notation is as follows.

• Slice of region of interest: n by n array of voxels.


• Total number of voxels in each slice is N = n2 .
• Each voxel has a width and height of 1 unit.
• For each radiographic view we record m pixels of data.
• The width of each pixel is ScaleF ac. If ScaleF ac = 1 then pixel width is the same as voxel
width.
• Number of radiographic angles (views): a.
• Total number of pixels in the radiograph: M = am
• Angle of the ith view (measured in degrees east of south): θi

49
region of interest

detector

Pixel
beam path k
k

Voxel j

PN
Sk = j=1 Tkj xj

total mass fraction of voxel j total mass


along in beam path k in voxel j
beam path k

Figure 3: Object space and radiograph space discretization.

• Object mass at voxel j is xj


• Recorded radiograph value at pixel k is bk

In this Lab we will be constructing matrix representations of the radiographic transformation


operators for example scenarios. Recall that an object can be represented by an N -dimensional
vector x and a set of radiographs can be represented by an M -dimensional vector b. What will be
the size of the corresponding matrix operator that maps object vector x to radiograph vector b?
Recall the definition of the matrix operator from the radiography discussion. Notice that particular
values for x and b are not necessary for computing the matrix of the radiographic transformation!

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

xn x2n ... xn2 xn x2n ... xn 2

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:

• Total number of voxels: N = 4 (n = 2).


x1 x3
• Total number of pixels: M = m = 2

• ScaleF ac = 2 x2 x4
• Number of views: a = 1 b2
• Angle of the single view: θ1 = 45◦
b1
Recalling that Tkj is the fraction of voxel j which
 projects perpendicularly
 onto pixel k, the matrix
1/ 1/
2 1 0 2
associated with this radiographic setup is T = 1 . Be sure and check this to see
/2 0 1 1 /2
if you agree! Hence, for any inputvector  x, the radiographic output is b = T x. Find the output
10
 0 
when the object is the vector x =   5 .

10

51
.

52
In Class Example:
We will first do an example together in class. Suppose you have the setup where

• Height and width of image in voxels: n = 2 (Total voxels N = 4)

• Pixels per view in radiograph: m = 2



• ScaleF ac = 2

• Number of views: a = 2

• Angle of the views: θ1 = 45◦ , θ2 = 135◦

1. Sketch this setup.

2. Calculate the matrix associated with the setup.

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.

Part I: Finding the matrix associated with a radiographic transformation, and


using the matrix to determine radiographic outputs.
Your instructor may assign one or more of the following scenarios.

1. Suppose you have the setup where

• Height and width of image in voxels: n = 2 (Total voxels N = 4)


• Pixels per view in radiograph: m = 2
• ScaleF ac = 1
• Number of views: a = 2
• Angle of the views: θ1 = 0◦ , θ2 = 90◦

(a) Sketch this setup.


(b) Calculate the matrix associated with the setup.
(c) Find the radiographs of the following objects. Remember you will need to convert these
objects into a vector in order to multiply it by T. Refer back to our First Example for
help!

4 3 0 1

6 1 1 0
x= y=

55
2. Suppose you have the setup where

• Height and width of image in voxels: n = 2 (Total voxels N = 4)


• Pixels per view in radiograph: m = 4

• ScaleF ac = 2/2
• Number of views: a = 1
• Angle of the views: θ1 = 45◦

(a) Sketch this setup.


(b) Calculate the matrix associated with the setup.
(c) Repeat step (b) using the code tomomap. How you can use this is first by opening the
mfile tomomap.m in MatLab or drag it into Octave. The code to do this is
T=full(tomomap(n,m,th,ScaleFac)) so for example if n = 4, m = 4, and the angles are
0, 20, and 90, with a scale factor of 1, you would write
T=full(tomomap(4,4,[0
√ 22.5 90],1))
Note to write 2, write sqrt(2).

3. Extra Credit Example: (this one requires some geometric maneuvering )


Suppose you have the setup where

• Height and width of image in voxels: n = 2 (Total voxels N = 4)


• Pixels per view in radiograph: m = 2
• ScaleF ac = 1
• Number of views: a = 2
• Angle of the views: θ1 = 0◦ , θ2 = 45◦

(a) Sketch this setup.


(b) Calculate the matrix associated with the setup.
(c) Repeat step (b) using the code tomomap. How you can use this is first by opening the
mfile tomomap.m in MatLab or drag it into Octave. The code to do this is
T=full(tomomap(n,m,th,ScaleFac)) so for example if n = 4, m = 4, and the angles are
0, 22.5, and 90, with a scale factor of 1, you would write
T=full(tomomap(4,4,[0 22.5 90],1))

56
Part II: Radiographs of Linear Combinations of Objects

4. Consider the objects from exercise 1 above: x (left) and y (right).

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.

(a) What is the radiograph of the object 3x?


(b) What is the radiograph of the object 0.5y?
(c) What is the radiograph of the object 3x + 0.5y?
(d) What do you notice? Can you generalize your observations?

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.

We will be using this cube as a working example:


Suppose our cube has vertices at:
(0, 0, 1), (2, 0, 1), (2, 3, 1),
(0, 3, 1), (0, 0, 0), (2, 0, 0),
(2, 3, 0), &(0, 3, 0).

We can write these in homogenous coordinates


by adding a dimension and in this case, we will just use 1.
So our homogeneous coordinates are:
(0, 0, 1, 1), (2, 0, 1, 1), (2, 3, 1, 1), (0, 3, 1, 1),
(0, 0, 0, 1), (2, 0, 0, 1), (2, 3, 0, 1), &(0, 3, 0, 1)
 
0 2 2 0 0 2 2 0
0 0 3 3 0 0 3 3
So we can represent this cube with the matrix: M =  1 1

1 1 0 0 0 0
1 1 1 1 1 1 1 1

To the left is a general


transformation matrix which
shows how different parts of
the matrix can change a wire-
frame object. We will now
give some examples of some of
transformations.

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.

8. Show that for a =1/2, e = 1/3, and


 j= 1 scales our cube down
 to the unit cube by multi-
1/2 0 0 0 0 2 2 0 0 2 2 0
 0 1/3 0 0 0 0 3 3 0 0 3 3
plying Ts ∗ ·M = 
 0
· =
0 1 0 1 1 1 1 0 0 0 0
0 0 0 1 1 1 1 1 1 1 1 1

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:

% Create rotation matrix


theta = 90; % to rotate 90 counterclockwise
R = [cosd(theta) -sind(theta); sind(theta) cosd(theta)];
% Rotate your point
point = [3; 5]; % This is an arbitrarily selected point
rotpoint = R*point;

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

Common misconceptions at this point in the lab:

• Misconception: Each radiographic view corresponds to a different transformation.


Truth: Multiple radiographic views are combined into a single radiographic image and is
the product of a single transformation acting on our object. The scenario details (number
and placement of views, voxelization of the object, etc.) and the domain and codomain
descriptions In×n (R) and Im×1 (R) should make this clear.

• Misconception: Objects cannot have negative valued entries.


Truth: Objects are vectors in I2×2 (R), with entries in the field of Real numbers. Our
particular application suggests that realistic objects must have non-negative entries. However,
not all meaningful objects need be non-negative. For example, two non-negative objects, u
and v, can have a difference object, d = u − v, which has negative entries. And d is a very
important object!

• Misconception: Radiograph pixel widths can be individually chosen.


Truth: In our scenarios, each pixel has the same width as every other pixel. Object voxels
have unit width and radiograph pixels have width ScaleFac.

• Misconception: Objects are matrices.


Truth: The space of radiographic objects In×n (R) is isomorphic to Mn×n (R).

4
Radiography/Tomography c 2016 T. Asaki, C. Camfield, H. Moon, M. Snipes

67
In Class Example:
Consider the radiographic setup described below.

• Height and width of image in voxels: n = 2

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

6.1.1 Pre-Lab 6 Questions:


Answer the following questions about this radiographic setup above, justifying your conclusions.
Answer the questions on this paper and I will go around and check your answers before class.
1. Are any nonzero objects invisible to this operator? If so, give an example. We say that an
object is nonzero if not all entries are zero. We say that an object is invisible if it produces
the zero radiograph.

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.1.2 In-Class Section of the Pre-Lab:

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

x2 x4 • Height and width of image in voxels: n = 2


(Total voxels N = 4)
• Pixels per view
√ in radiograph: m = 4
b2

• ScaleF ac = 2/2
• Number of views: a = 1
b1

• Angle of the views: θ1 = 45◦

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

• Height and width of image in voxels: n = 2


b3

(Total voxels N = 4)
b2

• Pixels per view in radiograph: m = 2


• ScaleF ac = 2
b1

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

6. Do you think this transformation is injective? Why or why not?

7. Do you think this transformation is onto? Why or why not?

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.

General Idea: If A = U ΣV T , we can use the outer product expansion to express


A = σ1 u1 v1T + σ2 u2 v2T + ... + σn u1 nvnT where σ1 ≥ σ2 ≥ ... ≥ σn > 0.

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!

7.2 Example 1: Image Compression


We will not have you explore data compression and choosing singular values in order to approximate
their image. Go to Blackboard and download the Lab 7 matlab file (SVD Compress) and the picture
provided. Upload these files to Octave. (You can use your own picture, but Octave works best
with true greyscale pictures. MatLab may be able to handle larger images.)

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!

2. Suppose A is 4 by 4 matrix with singular values σ1 = 2, σ2 = 1, σ3 = 10−1 and σ4 = 10−3 .


What is the condition number of A?

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?

7.4 Example 3: Noise Data


SVD can help decrease noise in data: When an image has noise (errors or random values),
sometimes a lower rank approximation can improve the quality of the data. While you may not get
the perfect completely-non-noise data back, reducing the noise can help you get a better underlying
picture of what is happening with the data. So sometimes, your goal is to reduce the noise.

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.

6. Find the transition matrix for this Board Game.


Hint: Note that the (1,1) entry of your matrix would be 13 since the probability you stay at
start would be 1/3 because you would stay if you roll a 1 or 2. the (5,1) entry would be 0
though because there is no roll that would take you from start to the 5th square.

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?

Turn over for one more question!

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

For example, let T : R2 → R3 be given by the matrix


 
1 1
A = 0 −1 .
0 −1

This has a one-sided inverse matrix P given by


 
1 2 3
P = .
0 5 6

P is the one-sided inverse because P Ax = x. That is P A = I2 as shown below.


 
  1 1  
1 2 3  1 0
PA = 0 −1 =
0 5 6 0 1
0 −1

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.

Theorem 8.1. Let V and W be finite-dimensional vector spaces and T : V → W a linear


transformation. If rank(T ) = dim(V ) then T T T is invertible8 .

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. Suppose V and W are finite-dimensional vector spaces and suppose T : V → W is a


linear transformation such that rank(T ) = dim(V ). Thus T : V → W has full rank since
rank(T ) = dim(V ) = n. This means that ran(T ) is a subspace of W with the same dimension
as V . So, we know that if we define the restriction of T T to ran(T) to be T˜T : ran(T ) → V , then
T˜T , having full rank maps onto V . That is, ran(T˜T ) = V . So, T T T : V → V has only a trivial
null space and therefore T T T has linear independent columns and thus by the Invertible Matrix
Theorem has an inverse.

Here is an alternate proof:

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:

- Size of the object: × .


- Number of pixels per view:
- Number of views:

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 .

(a) One strategy is to compose T with a linear transformation A : RM → RN so that the


product is invertible. (Can you see why this would be a good idea?) If T x = b and
A is any linear transformation (whose domain is RM ), then AT x = Ab. Since T is
one-to-one, we know that in order for the composition A ◦ T = AT to be invertible,
the only vector in ran(T ) that can be in null(A) is the zero vector. (Think about this!)
What other properties must A have so that AT is invertible?

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.

• Total number of voxels: N = 16 (n = 4).

• Total number of pixels: M = 24

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

Use the following code (with the modifications indicated!):

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:

• reshape(x,a,b) takes x and reshapes it into a a × b matrix.


• imagesc is a more general array plotting command than imshow. While imshow does a
good job at plotting arrays with square pixel size and nice grayscale, it will plot small
arrays too small to be seen!
• colormap(gray) tells imagesc to use a grayscale plot.
• caxis declares the grayscale limits, in just the same way that imshow does it. The
difference is that it is a separate command with imagesc.
• colorbar forces the plot to contain a colorbar reference.

Application to Brain Reconstruction


Now, let’s reconstruct some brain images from radiographic data. This section will guide you in
this process.

1. Collect the necessary provided files and place them in your working Octave/Matlab directory.

(a) Data File: Lab5Radiographs.mat


(b) Plotting Script: ShowSlices.m
(c) Octave/Matlab Code: tomomap.m

2. Choose whether to create a new script file (“.m” file) for all of your commands or to work at
the Octave/Matlab prompt.

3. Load the provided radiographic data with the following command.

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

9.1 Pre-Lab 9: Motivating Application for Eigenvalues and Eigen-


vectors
9.1.1 Review of Heat States in a (Vector) State Space
Recall, we in our notes on Vector Space, we introduced the application of diffusion welding. A
manufacturing company uses the process of diffusion welding to adjoin several smaller rods into a
single longer rod. The diffusion welding process leaves the final rod heated to various temperatures
along the rod with the ends of the rod having the same temperature. Every acm along the rod, a
machine records the temperature difference from the temperature at the ends to get heat states.
We can represent the heat states of the rod as a vector space.

Heat States in One Dimension


Now consider the function f : [a; b] → R that measures, along a rod of length l = b − a, the differ-
ence in temperature from the temperature at the ends of the rod (f (a) = f (b) = 0). The quantity
f (x) is the temperature of the rod at position x for any x in the interval [a, b].

Notice that the temperature distribution evolves in time.


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, more extreme temperature differences disappear first.
4. The long term behavior is that temperatures smooth out approaching f (x) = 0 (where 0 repre-
sents room temperature).

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 .

[u1 , u2 , ..., um ] = [f (a + ∆x), f (a + 2∆x), . . . , f (a + m∆x)].

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.

1. We define scalar multiplication in the usual componentwise fashion. Scalar multiplication


results in a change in amplitude only.

92
2. We define vector addition in the usual componentwise fashion. Addition can result in changes
in both amplitude and period.

9.1.3 The Heat Equation


This section may be of interest to students who have taken differential equations or are used to
solving system of equations. We will briefly discuss the motivation for eigenvectors and values at
the end before doing our Heat Equation Lab. The heat equation, or diffusion equation, (with fixed
unit diffusion coefficient) is
∂f ∂2f
= .
∂t ∂x2
1. A heat state vector f is a function of both position and time, though we often do not explicitly
write f (x, t) for clarity sake.

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

9.1.5 The Discrete Heat Equation, in t


The heat state u also changes over time. So we can write u = u(t), with a time dependence. That
2 u(t)
means we have from above ∂ ∂x 2 = D2 u(t).
Now, we use a similar argument to discretize ∂u
∂t .

∂u u(t + ∆t) − u(t)


≈ .
∂t ∆t
We want to find the diffusion operator E : Rm → Rm , for a fixed ∆t, so that
u(t + ∆t) = Eu(t) (That is, u(t + ∆t) is obtained via a matrix multiply). We put the above
discretizations into the heat equation to obtain:

u(t + ∆t) − u(t) 1


= D2 u(t).
∆t (∆x)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

state is given by E times the current state.

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

1. How can we interpret the values in column k of E?


Answer: The kth column shows how the heat at time t distributes to heat at time t + ∆t at
location k in the heat state. In particular, fraction 1 − 2δ of the heat at location k remains
at location k and fraction δ of the heat moves to each of the two nearest neighbor locations
k + 1 and k − 1.

2. How can we interpret the values in row k of E?


Answer: The kth row shows where the heat at time t + ∆t came from. In particular,
fraction 1 − 2δ of the heat at location k was already at location k and fraction δ came from
each of the location’s two nearest neighbors.

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.

9.1.6 Heat State Evolution


Now, we consider the evolution over more than one time step.

u(t + ∆t) = Eu(t)


u(t + 2∆t) = Eu(t + ∆t) = E(Eu(t)) = E 2 u(t)

This means k time steps later,


u(t + k∆t) = E k u(t)

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?

2. Note if we find E 2 or (E · E), we get


 
(1 − 2δ)2 + δ 2 2δ(1 − 2δ) δ2 0 ...
 2δ(1 − 2δ) (1 − 2δ)2 + δ 2 2δ(1 − 2δ) δ2 0
 
2  δ 2 2δ(1 − 2δ) (1 − 2δ) 2 + δ 2 2δ(1 − 2δ) . . . 
E = 
 0 δ 2 2δ(1 − 2δ) 2
(1 − 2δ) + δ 2 
 
.. .. .. ..
. . . . ...

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?

Now let’s explore morphing images or heat states.

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

1. On a new set of axes, sketch the difference v − w.

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.

• As the heat diffuses, sharpest temperature differences disappear first.

• 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

You might also like