Solution of Week 9 Lab (Prepared by Yuan Yin)
December 22, 2019
1 Exercise 1:
1.1 Sensitivity of the Least Square Problem:
(Run ‘ShowLSqV2.m’ and try to understand the output.)
1.2 QR Factorization:
(Run and try to understand ‘ShowQR’ and ‘qrExample. m’.)
1.3 Four Ways:
[1]:
%%file FourWays.m
function FourWays clc
A = [1, 1, 1; 1, 1, 0; 0, 1, 1; 1, 0, 0; 0, 0, 1];
b = [89; 67; 53; 35; 20];
x_true = [35.125; 32.5; 20.625];
% Using Cholesky Factorization:
I = chol(A’ * A);
x_chol = I \ (I’ \ (A’ * b));
% Using the QR Factorization:
[Q,R] = qr(A);
x_qr = R \ (Q’ * b);
% Using \:
x_backslash = A \ b;
% Using Singular Value Decomposition:
[U,S,V] = svd(A);
x_svd = V * (S \ (U’ * b));
% Calculating the error:
1
err_chol = norm(x_chol – x_true)
err_qr = norm(x_qr – x_true)
err_backslash = norm(x_backslash – x_true)
err_svd = norm(x_svd – x_true)
fprintf(‘As one can see, in this question, Cholesky factorization gives the␣
→smallest error.\n’); end
Created file ‘/Users/RebeccaYinYuan/MAST30028 Tutorial Answers Yuan Yin/WEEK
9/FourWays.m’.
[2]: FourWays err_chol =
7.9441e-15
err_qr =
2.5619e-14
err_backslash =
1.2809e-14
err_svd =
2.8643e-14
As one can see, in this question, Cholesky factorization gives the smallest
error.
2 Exercise 2:
2.1 Steepest Descent:
Note that using Steepest Descent, we can still manage to find a local minimal of the ‘banana’ function, but it is a very slow and inefficient process which involves a lot of function evaluations. Also, if you run the script ‘ShowBanana’, you will see a characteristic zig-zag trajectory. This is because for the ‘banana’ function, if you follow its steepest descent direction, you will actually get a curve. However, our step is a straight-line segment.
2
2.2 Gauss-Newton Method:
For the undamped Gauss-Newton method, a poor initial guess will result in more iterations. Note that there are also some warning messages saying that the ‘|residual|’ and the ‘cost’ will become infinity.
For the damped Gauss-Newton method, a poor initial guess will only result in more function evaluations.
3