Chapter 3

This is a MATLAB Live Editor version of the Fundamentals of Numerical Computation Jupyter Notebooks found at https://tobydriscoll.net/project/fnc/.

Example 3.1.1 Worldwide Temperature

Here are 5-year averages of the worldwide temperature anomaly as compared to the 1951-1980 average (source: NASA).

A polynomial interpolant can be used to fit the data. Here we build one using a Vandermonde matrix. First, though, we express time as decades since 1950, as it improves the condition number of the matrix.

As you can see, the interpolant does represent the data, in a sense. However it's a crazy-looking curve for the application. Trying too hard to reproduce all the data exactly is known as overfitting.

Example 3.1.2 Temperature Fit

Here are the 5-year temperature averages again.

The standard best-fit line results from using a linear polynomial that meets the least squares criterion.

If we use a global cubic polynomial, the points are fit more closely.

If we were to continue increasing the degree of the polynomial, the residual at the data points would get smaller, but overfitting would increase.

Example 3.1.3 Pi Rate

Finding numerical approximations to has fascinated people for millenia. One famous formula is

$\frac{\pi^2}6 = 1+ \frac 1{2^2} + \frac 1{3^2} + \cdots.$

Say is the sum of the first terms of the series above, and . Here is a fancy way to compute these sequences in a compact code.

This graph suggests that but doesn't give much information about the rate of convergence. Let be the sequence of errors. By plotting the error sequence on a log-log scale, we can see a nearly linear relationship.

This suggests a power-law relationship where , or .

In terms of the parameters and used above, we have

It's tempting to conjecture that asymptotically. Here is how the numerical fit compares to the original convergence curve.

Example 3.2.1 Normal Instability

Because the functions , , and are linearly dependent, we should find that the following matrix is somewhat ill-conditioned.

Now we set up an artificial linear least squares problem with a known exact solution that actually makes the residual zero.

Using backslash to find the solution, we get a relative error that is about times machine epsilon.

If we formulate and solve via the normal equations, we get a much larger relative error. With , we may not be left with more than about 2 accurate digits.

Example 3.3.1 QR Factorization

MATLAB gives direct access to both the full and thin forms of the QR factorization.

Here is the full form:

We can test that is orthogonal.

With a second input argument given, the thin form is returned.

Now cannot be an orthogonal matrix, because it is not even square, but it is still ONC.

Example 3.4.1 Householder QR Factorization

We will use Householder reflections to produce a QR factorization of the matrix

Our first step is to introduce zeros below the diagonal in column 1. Define the vector

Applying the Householder definitions gives us

By design we can use the reflector to get the zero structure we seek:

Now we let

We are set to put zeros into column 2. We must not use row 1 in any way, lest it destroy the zeros we just introduced. To put it another way, we can repeat the process we just did on the smaller submatrix

We now apply the reflector to the submatrix.

We need two more iterations of this process.

We have now reduced the original to an upper triangular matrix using four orthogonal Householder reflections: