Description
Statistical and Mathematical Methods for Artificial Intelligence
2021-2022
Homework 1: Linear Algebra and Floating Point Arithmetic
Direct Methods for the solution of Linear Systems.
1. Given a matrix A ∈ Rn×n and the vector xtrue = (1,1,…,1)T ∈ Rn, write a script that:
• Computes the right-hand side of the linear system b = Axtrue.
• Computes the condition number in 2-norm of the matrix A. It is ill-conditioned? What if we use the ∞-norm instead of the 2-norm?
• Solves the linear system Ax = b with the function np.linalg.solve().
• Computes the relative error between the solution computed before and the true solution xtrue. Remember that the relative error between xtrue and x in Rn can be computed as
• Plot a graph (using matplotlib.pyplot) with the relative errors as a function of n and (in a new window) the condition number in 2-norm K2(A) and in ∞-norm, as a function of n.
2. Test the program above with the following choices of A ∈ Rn×n:
• A random matrix (created with the function np.random.rand()) with size varying with n = {10,20,30,…,100}.
• The Vandermonde matrix (np.vander) of dimension n = {5,10,15,20,25,30} with respect to the vector x = {1,2,3,…,n}.
• The Hilbert matrix (scipy.linalg.hilbert) of dimension n = {4,5,6,…,12}.
Floating Point Arithmetic.
1. The Machine epsilon is the distance between 1 and the next floating point number. Compute , which is defined as the smallest floating point number such that it holds:
Tips: use a while structure.
2. Let’s consider the sequence . It is well known that:
lim an = e n→∞
where e is the Euler costant. Choose different values for n, compute an and compare it to the real value of the Euler costant. What happens if you choose a large value of n? Guess the reason.
1
3. Let’s consider the matrices:
Compute the rank of A and B and their eigenvalues. Are A and B full-rank matrices? Can you infer some relationship between the values of the eigenvalues and the full-rank condition? Please, corroborate your deduction with other examples.
Tips: Please, have a look at np.linalg.
2
Reviews
There are no reviews yet.