Homework 3, due Oct 12
- Computer Problem 3.1 of the text, p. 152. You can use Matlab's
built-in vander and polyval to set up the least squares
problems, but this is not necessary. If you want, you can use
fliplr and flipud to make the notation of the Vandermonde
matrix conform to the notation of the text, but this is not necessary
either. You can use any method you like to solve the least squares
problem; the easiest is Matlab's \. Please plot all the polynomial
approximations on the same graph, for example using hold on.
Collect the commands that do all this in a function,
with comments, where the input to the function consists of the two data
vectors t and y (don't assume they have length 6, but
write the code more generally), and then call it for the data on p.152.
- Write a function to compute the least squares solution of
Ax ~ b using the method of Givens rotations. You
do not have to compute the matrix Q (the product of
the Givens transformations), since you can apply the
transformations to the right hand side b at the same time as they are
applied to triangularize A. This is most easily done by
collecting A and b into a single matrix and applying
the transformations to both at once. Your function should not call the
cosine or sine functions; it should use the formulas at the top of
p.128 of the text. Also, don't put the Givens transformations into
a matrix and multiply with it - this is much too expensive. Just
apply the transformations to the individual rows of [A b].
Each Givens transformation involves replacing two rows by linear
combinations of the same two rows, introducing a single zero in the desired
position. When programming in Matlab, try to avoid loops as much as possible
and use vector operations when you can.
After applying all the necessary Givens transformations,
the resulting matrix should be triangular, except for very small rounding
errors where you expect 0's. You can set these to 0 (make sure they are
tiny though!) before using \ to solve the triangular system.
Test your code on random matrices and compare it with what you get
when you use a built-in method such as using \ on the original
data. If the least squares solutions do not agree to most digits on
random examples, there is a bug in your code.
- Computer problem 3.13 of the text, p.156, parts (a), (c), (d), (h)
only. For (d) use your function from the previous question; for the others,
you can use the built in chol, qr, svd. As with the other questions,
collect the commands that make the comparison inside a function; in
this case the input parameter should be epsilon.