Title: Visualizing Matrices
1- Visualizing Matrices
- John Peterson
- Yale University
- Languages for Mathematics
- Education
- www.haskell.org/edsl
2Turning Math into Pictures
- I study languages that allow people to
- use computers in new ways.
- Interactive pictures give us a way of
- showing the underlying intuition behind
- the mathematics.
3Review
- What you should know
- What a matrix is
- How to add and multiply matrices
- Determinates
- Inverting matrices
- Triangle Area theorem
4Using a 2x2 Matrix Lens
- We use a matrix as a lens through which we
- view an image.
- A 2-d image is a mapping from points in the
coordinate plane onto colors.
5Adding a Matrix
- Now add a transformation between the observer
(you) and the picture
x
Observation point
Image color
Image point
Transformation matrix
6An Example
- How does the image change as parameters change?
2 4
1 2
x
Image point
Observation point
Image color
2 x Identity matrix
7Live demo time
Run the demo 01-basic-matrix Make some
observations!
8So what did we learn?
- Lines always remain straight
- Origin doesnt move 0 0 x M 0 0 no
matter what M - Angles may change
- Image may completely disappear
- But do we have any intuition about what
- a, b, c, and d do??
9Whats in the Matrix
- One way to take apart the matrix is to apply it
- to some specific values, the x and y units,
- 1 0 and 0 1
x
???
10Whats in the Matrix
- One way to take apart the matrix is to apply it
- to some specific values, the x and y units,
- 1 0 and 0 1
x
a b
11Whats in the Matrix
- One way to take apart the matrix is to apply it
- to some specific values, the x and y units,
- 1 0 and 0 1
x
???
12Whats in the Matrix
- One way to take apart the matrix is to apply it
- to some specific values, the x and y units,
- 1 0 and 0 1
x
c d
13Units
- When we plot the point (a,b) on the
- warped picture were seeing the image of
- the x unit (c,d) is the image of the
- y unit.
Lets see how this works! Well mark the units in
the original picture and their images Run the
demo 02-show-points
14Inverting a Matrix
- What does it mean to invert a matrix?
- Visually, it is how you undo an image warp.
- Lets try and invert the following matrix
1.31 1.14 0.26 -0.44
15Inverting a Matrix
Transformed image
Original image
Transform this back to the original
16Inverting a Matrix
- Run 03-inverse and then check your answer
1.31 1.14 0.26 -0.44
?
x
17Determinates
- What is the meaning of a determinate?
- Lets look at the image of the unit square.
- Note that the vertices of the square are
- (0,0) (a,b) (ac, bd) (b,d)
- Can you see the connection between
- the determinate and the square in
- the example 04-determinate?
18Determinates
- A (2x2) determinate indicates how the
- area of a figure changes under the image
- of a transformation.
- A determinate of 0 indicates that the
- figure collapses to a point or line.
- A 3x3 determinate indicates change in
- 3-dimensional volume.
19Measuring a Line
- If a 3x3 determinate measures the area of
- a triangle, we can use a 2x2 to measure
- the length of a line.
- Given a line from A to B, construct the
- following matrix
-
Run 05-length to see this
20The Unit Circle
- The unit circle is a circle with radius 1
- centered at the origin.
- What is the diameter of this circle?
- Lets walk around the circle starting
- at (1,0). After walking a distance d, where
- are you?
- If this point is (a,b) then what is a b ?
2
2
21Sine and Cosine
- Run 06-sine.cs
- This shows you two functions
- if x is the distance traveled around the
- circle, then (cos(x), sin(x)) is the
- coordinate on the circle
- Note sin(x) and cos(x) are between
- -1 and 1
-
22Factoring A 2x2 Matrix
X scaling
Y scaling
23Factoring A 2x2 Matrix
Skew
Rotation
24An Exercise
- Find the inverse and determinate of
- each one of these matrices.
M
M
s
x
M
M
r
y
25Decomposing a Matrix
- We can take apart a 2x2 matrix and
- express it as a product of these 4
- matrices
M x M x M x M
y
x
s
a
26Why Decompose?
- These simple matrices are easy to understand
they have very useful - effects on an image
- Run 07-factored to see how this works
- We can do anything to the image with
- the product of these 4 matrices that
- can be done with any other 2x2 matrix
- Run 08-factored-inverse to see more
27Inverting a product matrix
- Lets invert our matrix
- This is right, isnt it?
-
-1
-1
-1
-1
-1
M x M x M x M
y
x
s
a
28Oops!
- We blew it! If a matrix is a product of
- other matrices, you have to reverse the
- order of the inverses
-1
-1
-1
-1
-1
M x M x M x M
x
y
s
a
29Translation
- Unfortunately a 2x2 matrix cant move
- things around - point (0,0) never moves.
- The solution use special 3x3 matrices
x y 1
Add a 1 to each point
Extra row
30Translation
Example multiply M x 5 2 1
T(2,3)
Run 09-translation to see this
31Matrix Computers
- Did you know that many computers have
- special hardware for multiplying matrices?
- Some computers do almost nothing except
- multiply lots and lots of these 3x3 (4x4 in
- most cases for 3D points)
- What do these computers look like?
32Matrix Computers?
33Matrix Computer!
34Building an Animation
- We can make a short animated movie
- by using matrices to move around
- images.
- Write equations like this for each of the
- parameters in the matrix
- x if time lt 2 then 0 else
- if time lt 4 then (time-2) 50 else
- 100
-
35Some Math
- Its often easiest to map some interval
- of time onto the interval (0, 1).
- How would we map (2,5) onto (0,1)?
- (Hint you could solve this with matrices!)
f(t) (t-2)/3 f(2) 0, f(5) 1
36A Lame Animation
Run 11-animation to see this
sx if t lt 8 then 1 else (1-(t-8)/2) sy sx rot
if t lt 3 then 0 else if t lt 5 then
((t-3)/2)2pi else 0 skew if t lt 5 then
0 else sin((t-5)(t-5)) (xt,yt) if t lt 5 then
(30t, 10t) else (150, 50)
37Thank You!
- We hope you enjoyed this presentation.