Please answer the following questions in complete sentences in a clearly prepared manuscript and submit the solution by the end of class on Thursday, September 6th, 2012.
Please identify anyone, whether or not they are in the class, with whom you discussed your homework. This problem is worth 1 point, but on a multiplicative scale. (Note that collaboration is not allowed on the bonus question below.)
Compute the following by hand or using Matlab.
a) ?
b) ones(1000,1) [1:1000]' ?
(Optional extra question – worth no points – who is always credited with discovering a very efficient way to compute this as a child?)
c) , ? ?
d) , ? ?
Let and be invertible matrices. We’ll prove that the inverse of is easy to determine!
a) Show that the inverse of
\bmat{ 1 & a \\ 0 & 1 }
is
\bmat{ 1 & -a \\ 0 & 1 }.
b) Now, show that the inverse of
\bmat{ \mI & \mA \\ 0 & \mI }
is
\bmat{ \mI & -\mA \\ 0 & \mI }.
c) Recall that for general and , not those in the problem!, . Use this fact, and the result of problem b to determine the inverse to when and are invertible. Alternatively, give the inverse of . Hint: think about diagonal matrices!
This problem will be more difficult if you haven’t used Matlab before, so get started early! It’s designed to teach you about writing for loops to construct a matrix operation for a particular task.
Consider the following problem. We have a pixel image. Each pixel is a real-valued number between and . However, I want to show this on an iPhone and I only have a pixel area to show the image. In order to reduce the size of the image, I want to average groups of 4 pixels. In this problem, we’ll create a Matlab program to do this
Let’s work through a smaller example first. For the image, represented here by a matrix-like array:
\bmat{ x_{1} & x_2 & x_3 & x_4 \\ x_5 & x_6 & x_7 & x_8 \\
x_9 & x_{10} & x_{11} & x_{12} \\
x_{13} & x_{14} & x_{15} & x_{16} }
I want to compute
\bmat{ (x_1 + x_2 + x_5 + x_6)/4 & (x_3 + x_4 + x_7 + x_8)/4 \\ (x_9 + x_{10} + x_{13} + x_{14})/4 & (x_{11} + x_{12} + x_{15} + x_{16})/4 }.
We will solve this problem using a matrix-vector product.
a) Suppose I call:
\begin{matrix} y_1 = (x_1 + x_2 + x_5 + x_6)/4 & y_2 = (x_3 + x_4 + x_7 + x_8)/4 \\
y_3 = (x_9 + x_{10} + x_{13} + x_{14})/4 & y_4 = (x_{11} + x_{12} + x_{15} + x_{16})/4. \end{matrix}
Further, suppose we consider the vectors and to be the new image and old image, respectively. Write down the matrix such that .
In the remainder of the problem, we’ll work through how to do this for a particular image in Matlab.
b) Download http://www.cs.purdue.edu/homes/dgleich/cs515/homeworks/smallicon.mat and type
load smallicon.mat
in Matlab. You should get a matrix . What is the sum of diagonal elements of ? (If you wish to use another programming language, feel free, but make sure you can do the same things in it. I’ve provided http://www.cs.purdue.edu/homes/dgleich/cs515/homeworks/smallicon.txt as a text file for use in other languages.)
c) Matlab has a command for viewing a matrix as an image. Run the following commands:
imagesc(X)
The result looks really weird, right? That’s because Matlab is making up a color for each pixel. We can tell it to use a greyscale colormap by executing:
colormap(gray)
Save the resulting Matlab figure as an image to include in your homework. (You’ll need to do this for future homeworks, so make sure you know how to do it on this one!)
d) In what follows, we’ll talk about two different types of indices. The image index of a pixel is a pair that identifies a row and column for the pixel in the image. The vector index of a pixel is the index of that pixel in a linear ordering of the image elements. For instance, above, pixel (3,2) has linear index . Also, pixel (1,4) has index . Matlab can help us built a map between pixel indices and linear or vector indices:
N = reshape(1:(4*4), 4, 4)';
This creates the pixel index to linear index for the problem above because
N(1,4)
N(3,2)
return the appropriate entry.
In your own words, explain what the reshape operation does. What happens if you omit the final transpose above and try:
N = reshape(1:(4*4), 4, 4);
instead?
e) Now we need to construct the matrix in order to reduce the size of . Suppose we call the output vector and the output image . I’m giving you the following template, that I hope you can fill in. Feel free to construct any way you choose, but the following should provide some guidance.
NX = <fill in>; % the map between pixel indices and linear indices for X
NY = <fill in>; % the map between pixel indices and linear indices for Y
for i=1:32
for j=1:32
xi = <fill in>; % the index of the pixel i,j in the vector x
yij = <fill in>; % the resulting location of pixel in the matrix Y
yi = <fill in>; % the index of the linear pixel in the vector y
A(yi,xi) = 1/4; % place the entry of the matrix
end
end
f) In order to use the matrix we created, we need to convert the matrix into a vector! The reshape operation helps here:
x = reshape(X',32*32,1);
We can now rescale the image by multiplying by and reorganizing back into a matrix .
y = A*x;
Y = reshape(y,16,16)';
Show the image of . Does that look correct?
g) The Matlab way to solve this problem is to use the built in routine interp2. In this case, you can call
Ym = interp2(X,-1)
to accomplish the same goal and save the output to a Matlab variable Ym.
Do Y and Ym agree? If not, can you comment on their differences?
h) Show all of your code for this problem.
For the following questions, either prove that the statement is correct, or show a counter-example.
a) The product of two diagonal matrices is diagonal.
b) The product of two upper triangular matrices is upper triangular
c) The product of two symmetric matrices is symmetric.
d) The product of two orthogonal matrices is orthogonal.
There are a tremendous number of matrix norms that arise. An interesting class are called the orthgonally invariant norms. Norms in this class satisfy:
\normof{\mA} = \normof{\mU \mA \mV}
for square orthogonal matrices and . Recall that a square matrix is orthogonal when , i.e. .
Show that is orthogonally invariant.
Consider the following function:
f(\mA) = \max_{i,j} |A_{i,j}|.
a) Show that is a matrix norm.
b) Show that does not satisfy the sub-multiplicative property.