
Linear Algebra and Geometry - Scientific Computing
Exercise session 3
Topics: linear systems
1. Select the output display format long and solve the linear system Ax =b, where Ais the Hilbert
matrix of order n= 5,10,15 and bsuch that the solution xis a vector of all ones. For each ncompute
the relative error of the solution and the conditioning number using ∞-norm. Comment the results.
2. Write a MATLAB function called elleu which computes Land Ufactors of the decomposition A=LU.
Subsequently, generate the matrix Aof order n= 100, whose elements are aij = max(i, j) and b
such that the solution xis a vector of all ones. Finally, solve the linear system Ax =b, using the
decomposition A=LU from the function elleu at first, then by means of the decomposition PA =LU
from MATLAB function lu.
In both cases compute the ∞-norm of the relative error the solution. Based on the obtained results,
deduce what solution is more accurate, motivating your answer.
3. Assemble the matrix Aof order n= 100, whose elements are aij =imax(i, j ). Find the matrices
P,Land Ufrom the decomposition PA =LU of the matrix Aby means of the MATLAB function lu.
Subsequently, use above factors to invert the matrix A. Verify the result using the MATLAB function
inv.
4. Assemble a matrix Aof order n= 100, whose elements are pseudo-random numbers. Efficiently solve
(minimizing the number of arithmetic operations) the following linear systems:
Ax1=b1
Ax2=b2
Ax2=b3
...
Ax30 =b30
sharing the same matrix A; let b1such that the corresponding solution x1is a vector of all ones and
bi=xi−1,i= 2,...,30. Subsequently, solve each system using MATLAB command \. Comparing the
computation time of both procedures, using MATLAB commands tic and toc, and comment the results.
5. Assemble the tridiagonal matrix Bof order n= 100, whose main diagonal elements are all equal to
10, while the sub-diagonal and super-diagonal elements are equal to −5 and 5 respectively. Bearing in
mind that Bis not singular, therefore A=BTBis symmetric and positive-definite, use the MATLAB
function chol to find the Choleski decomposition A=RTR. After that, use the above decomposition
for calculating the inverse of Aand for solving the linear system Ax =b, where bsuch that the
solution xis a vector of all ones. Verify the results using MATLAB commands inv and \.
6. Assemble a pseudo-random matrix Aof order n, and compute the QR decomposition of A. Later use
the factors Qand Rfor solving the linear system Ax =b, where bsuch that the solution xis a vector
of all ones. Compute the ratio between the computational costs for solving the linear system by means
of PA =LU decomposition and QR decomposition, by varying the order of the matrix (for instance
n= 100,200,...,500 and n= 1000,2000,...,5000). Comment the results.
7. Consider the following overdetermined linear system:
1