1 Description and Objectives
In this (our final) lab, you will put together many of the matrix operations that you have
learned to produce an application that can solve Least Squares problems from scratch.
This is a farily involved lab. (Sorry.) But on the bright side, you will have a good while to
1. Understand DenseMatrix class operations from previous lab.
2. Implement a Cholesky Factorization routine for solving (dense) symmetric positive definite
3. Understand how to use the Cholesky Factorization to solve a linear system
4. Learn how to create the normal equations that are required for a least squares curve
fitting, including operations for matrix transpose
5. Solve the linear system(s) necessary to perform a least-squares curve fitting
2 Cholesky Decomposition
Our first step towards our goal of having a least squares solver is to build a class that can
factorize a symmetric positive definite matrix into lower and upper triangular parts: A =
LLT . All of the operations today will use (and extend) the DenseMatrix classes you wrote
for Lab 11.
Implement the constructor for the CholeskyDecomposition class I gave you. You may wish
to use the matrix in the file C1.txt, which has a decomposition:
3 Solving Linear Systems
Write a solve method for the CholeskyDecomposition class that takes a DenseMatrix
as input and outputs a DenseMatrix as the solution to the matrix system
AX = B
The pseudocode TriangularSolve given in class today should come in quite handy. You can
use the file RHS.txt, which has b = [32, 26, 38, 30]T You can (if you wish) assume that B has
only one column (and then so would the matrix returned by your method) Note however, that
this is not necessary...
4 Useful Code
Write a (simple) method for your DenseMatrix class that returns a copy of the transpose of
5 Least Squares
You are a master brewmaker, and you would like to form a functional relationship to help you
predict the “yummyness” of a beer y as a function of the amount of hops x you put in the beer.
Your experiments yielded the measures given in Table 1, as well as hours of enjoyment:
Table 1: Measurements of Yummyness
Using the codes you have developed, compute a best linear fit for these measurements: y =
. What are the coefficients ? Plot the data as well as your (linear) approximation
Using the codes you have developed, compute a best quadratic fit for these measurements: y =
. What are the coefficients ? Plot the data as well as your (quadratic)
approximation to it.
6 Bonus Problem
Let e(n) be the total error in the approximation () if a basis of polynomials up to degree
n − 1 is used. Plot e(n) as a function of n for the data in Table 1
7 Lab Deliverables
• Three files: Lab12.java, DenseMatrix.java, CholeskyDecomposition.java. You
should not have to change (too much) the code in Lab12.java, though you may find it
useful to comment parts out while you do the code development. Also, your estimates
and plots for the problems in Section 5.
8 Problem Set (In addition to those from Lab11)
For the following two matrices, provide a Cholesky decomposition, or prove that the matrix is
28-1 (a), (b), (c).
8.1 Extra Credit
28-1 (d) (e)