Correspondent lab lectures: 1, 2, 3

Direct Methods for the Solution of Linear Systems

  1. Given a matrix and the vector , write a script that:
    • Computes the right-hand side of the linear system .
    • Computes the condition number in 2-norm of the matrix . Is it ill-conditioned? What if we use the -norm instead of the 2-norm?
    • Solves the linear system with the function np.linalg.solve().
    • Computes the relative error between the solution computed before and the true solution . Remember that the relative error between and in can be computed as
  • Plot a graph (using matplotlib.pyplot) with the relative errors as a function of and (in a new window) the condition number in 2-norm and in -norm, as a function of .
  1. Test the program above with the following choices of :
    • A random matrix (created with the function np.random.rand()) with size varying with .
    • The Vandermonde matrix (np.vander) of dimension with respect to the vector .
    • The Hilbert matrix (scipy.linalg.hilbert) of dimension .

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.

  1. Let’s consider the sequence . It is well known that:

where is the Euler constant. Choose different values for , compute and compare it to the real value of the Euler constant. What happens if you choose a large value of ? Guess the reason.

  1. Let’s consider the matrices:

Compute the rank of and and their eigenvalues. Are and 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


Other assignments: