Starting from:
$30

$24

NUMERICAL COMPUTATION Homework 5:

The purpose of this homework is to see the relationship between the condition number and the numerical error when solving linear least-squares problems.

First, implement the following methods for least-squares, which you’ll use in the next exercise.

    1. Method of Normal Equations (uses the Cholesky factorization)

    2. Method based on the Thin QR factorization

Next, load the given matrix into memory. Call the matrix A,

A = a1an  ;
(1)
where ai 2 Rm is the ith column of A. De ne the matrices A1; : : : ; An as:

Ak = a1ak  ;  k = 1; : : : ; n:
(2)
That is, Ak contains the  rst k columns of the matrix A (that you loaded into memory). Now, generate the error data that you’ll analyze. For k from kmin = 40 to kmax = 65:

    1. Report the size, rank, and condition number of Ak.

    2. Generate 100 random vectors bi 2 Rm. For each bi,

        (a) Use the built-in equation solver1 to compute the least-squares minimizers given Ak and bi. Call this vector xtrue, because we’re just gonna trust the software on this one.

        (b) Use your Normal Equation solver to compute the least-squares minimizer, xNE. Compute the relative error with xtrue:
errk;iNE =
kxNE   xtruek2
(3)

kxtruek2





(c) Use your QR solver to compute the least-squares minimizer, xQR. Compute the relative error with xtrue:
errk;iQR =
kxQR   xtruek2
(4)

kxtruek2





    3. For each of QR and Normal Equations, compute the average error over all the bi. Make two plots on a semilogy scale:

    • the average error versus k for both QR and the Normal Equations,

    • the condition number of Ak versus k.

Now tell me what’s going on. More speci cally:

1. What is the relationship between the error using QR versus the Normal Equations?


    • numpy.linalg.lstsq in Python, linsolve in Matlab

1
    2. What is the relationship between the errors and the condition number of Ak?

    3. Suppose your matrix A is ill-conditioned. Which method is more favorable?

BONUS (10 POINTS): Take kmax up to 100. Something should break. What broke and why did it break? Any xes?

BONUS (10 POINTS): Repeat this exercise (de ne the Ak’s, etc.) with some other tall matrix you nd in the wild. There are lots of examples from data science. What are the results? Why was the matrix you chose interesting? Any origin stories for the matrix (like, insight from the data that generated it) for why the condition number behaves the way it does?





















































2

More products