Reference no: EM134374
Exercise 1 This le contains two arrays, A and B. Each of these arrays contains a number of 50 50 grayscale images of faces. The array A contains a library of 20 faces and has size 50 50 20, and the array B contains 4 test faces and has a size 50504. In this exercise, you should be plotting and reshaping these images often to make sure that everything makes sense! You can plot an image in A using the following command:
>> imagesc(A(:,:,1)), colormap gray;
Another nice way to plot is:
>> pcolor((A(:,:,16))), shading interp, colormap(gray), set(gca,'Xtick',[],'Ytick',[])
>> axis ij
(a) Reshape the A array so that it is size 202500 and each row is one of the images. (Be careful if you use the reshape command, since you will want to reshape into a 2500 20 array and then take the transpose!).
(b) Compute the economy sized SVD of the reshaped A matrix.
returned by svd has the singular values on the diagonal.
(c) Images 1 5 of A are all of Clooney, images 6 10 are of Obama, images 11 15 are of Thatcher, and images 16 20 are of Damon. Compute the average face for each of Clooney, Obama, Thatcher, and Damon. Project these onto the eigenface directions obtained above. Recall that since we reshaped images into row vectors, projecting onto eigenface directions is the same as multiplying with the V matrix from the SVD.
(d) Reshape the B array of test images so that it is size 4 2500 (use the same method that you used for array A). Project each of these four test images onto the eigenface directions to obtain four vectors, each of length 20. For each of the test images, compute the distance in eigenface space to the average Clooney, Obama, Thatcher, and Damon faces. Given two vectors f1 and f2 in eigenface space, you may compute the distance using something like: >>
distance = norm(f1-f2);.
Exercise 2 This data contains the velocity (meters/second) as a function of time (seconds). Find the acceleration as a function of time. To do this, you will need to dierentiate the data as a function of time. Do this in the following ways (it is interesting to plot the following approximate derivatives on the same plot to see the various features!):
(a) Use an O(t2) accurate scheme on the raw data. Please use a central dierence on the interior points, and an O(t 2) forward/backward dierence scheme on the end points.
(b) Fit a spline through the data with t=0:0.01:30; and nd the O(t2) and O(t4) derivative (in both cases, use a O(t2) forward/backward dierence scheme at the end points).
(a) Integrate using a trapezoidal rule. Use the cumtrapz command to compute the cumulative integral at each intermediate time.
(b) Use a spline with t=0:0.01:30 and a trapezoidal rule to evaluate the integral. Again, use the cumtrapz command.
(c) Create a function that returns the spline interpolation using function handles. Integrate this function with the quad command from t = 0 to t = 30.