Docsity

Linear Algebra and Geometry - Scientific Computing: Exercise Session 3 - Prof. Carlini, Esercizi di Algebra Lineare e Geometria Analitica

Toggle sidebar
bg1
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
pf2

Anteprima parziale del testo

Scarica Linear Algebra and Geometry - Scientific Computing: Exercise Session 3 - Prof. Carlini e più Esercizi in PDF di Algebra Lineare e Geometria Analitica solo su Docsity!

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 A is the Hilbert matrix of order n = 5, 10 , 15 and b such that the solution x is a vector of all ones. For each n compute the relative error of the solution and the conditioning number using ∞-norm. Comment the results.
  2. Write a MATLAB function called elleu which computes L and U factors of the decomposition A = LU. Subsequently, generate the matrix A of order n = 100, whose elements are aij = max(i, j) and b such that the solution x is 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 A of order n = 100, whose elements are aij = i max(i, j). Find the matrices P, L and U from the decomposition PA = LU of the matrix A by 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 A of order n = 100, whose elements are pseudo-random numbers. Efficiently solve (minimizing the number of arithmetic operations) the following linear systems:         

Ax 1 = b 1 Ax 2 = b 2 Ax 2 = b 3 ... Ax 30 = b 30

sharing the same matrix A; let b 1 such that the corresponding solution x 1 is 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.

  1. Assemble the tridiagonal matrix B of 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 B is not singular, therefore A = BT^ B is symmetric and positive-definite, use the MATLAB function chol to find the Choleski decomposition A = RT^ R. After that, use the above decomposition for calculating the inverse of A and for solving the linear system Ax = b, where b such that the solution x is a vector of all ones. Verify the results using MATLAB commands inv and .
  2. Assemble a pseudo-random matrix A of order n, and compute the QR decomposition of A. Later use the factors Q and R for solving the linear system Ax = b, where b such that the solution x is 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.
  3. Consider the following overdetermined linear system:

x 1 + 2x 2 + 3x 3 + 4x 4 = 1 −x 1 + 4x 3 + x 4 = 2 3 x 1 + 5x 2 + x 3 = 3 2 x 1 − x 2 + x 4 = 4 x 1 + x 2 − x 3 + x 4 = 5 2 x 1 − x 2 + 3x 4 = 6

Compute the rank of the matrix of the coefficients of the system. Subsequently, compute the solution of the system in the least-squares sense. Verify the result using the Matlab command .

  1. Implement the Gram-Schmidt orthonormalising method and use it to construct an orthonormal basis of R^5 starting from the following linear independent vectors:

v 1 = (4, 2 , 1 , 5 , −1)T^ , v 2 = (1, 5 , 2 , 4 , 0)T^ , v 3 = (3, 10 , 6 , 2 , 1)T

v 4 = (3, 1 , 6 , 2 , −1)T^ , v 5 = (2, − 1 , 2 , 0 , 1)T Let Q the matrix whose columns are the vectors generated by the procedure. Verify the results of the procedure through Q orthogonality.