Homework 2, due Sept 27 at midnight
If you have not already done so, please join the class mailing list!
Homework may be given to me in class or in my office, or
left under my office door. Please do not leave homework in my
lobby mailbox or send it by email.
Please staple all pages together. Late homework will be
penalized 20%. Homework will not be accepted more than one week late,
except in special circumstances.

Write a Matlab function (NOT a script) with two input arguments
 a string, which is the name of a JPEG file containing an image to
be approximated
 an integer, which is the "approximate rank" to be used
and two output arguments
 a string, which is the name of the new JPEG file for the
approximated image,
 a struct, which has three fields,
e.g. compressed.S, compressed.U, compressed.V, namely the singular
values and vectors needed to reconstruct the lowrank approximate picture
The function must have comments explaining the inputs and outputs
and what the function does, which is the following:
 import the file into Matlab using imread, where it
is stored as a uint8 (8bit unsigned integer) array
 convert this to the ordinary double array format using double
 compute the SVD of this array
 compute the low rank approximation matrix from the retained singular
values and corresponding singular vectors
 convert this back to the uint8 format using uint8
 save the low rank image as a new JPEG file using imwrite
 construct the second output argument, which would be useful for saving the
approximated image efficiently
Furthermore, if the approximate rank input argument is 0, the function should display
the singular values in a semilogy plot and prompt the user to enter
the desired approximate rank using input.
Test your function thoroughly on one or more grayscale images from the web (not the
basket picture) or from your personal collection of pictures and
 check out how good your low rank images are by viewing them outside Matlab
 for one image, print the original and several low rank approximations and attach them to the
homework along with a semilogy plot of the singular values and a
listing of the Matlab function (but not the command session)
 Comment in writing on how much Matlab storage space your second output argument needs, compared to the space required in Matlab for the original image (either the uint8 or double array,
but specify which)
I got the basket image a while ago from a web page that no longer exists.
When I tried to do this on the PC in my office, it didn't work.
Somehow, the image got swallowed up in a much larger picture,
most of which is blank. However, it worked on the classroom PC and on the
Sun in my office.
Use help to learn the syntax of Matlab commands
 Referring to Chapter 4 of
Numerical Computing
with IEEE Floating Point Arithmetic, (which is on reserve in
the library) answer the following
 Determine the IEEE single format floating point
representations for the numbers 2, 1000, 23/4, (23/4) times 2^(100),
and (23/4) times 2^(135).
 What is the smallest positive integer that cannot be stored
exactly as an IEEE single precision number?
 (Exercise 4.3): Give an algorithm that,
given two IEEE single format floating point
numbers x and y, determines whether x is less than, equal to,
or greater than y, by comparing their representations bitwise
from left to right, stopping as soon as the first differing bit is
encountered. The fact that this can be done easily motivates
biased exponent representation. It also justifies referring to the
left end of the representation as the "most significant" end.
(You do not need to program the algorithm; just write out the idea on
paper.)