Source code for cla_utils.exercises10

import numpy as np
import numpy.random as random


[docs]def arnoldi(A, b, k): """ For a matrix A, apply k iterations of the Arnoldi algorithm, using b as the first basis vector. :param A: an mxm numpy array :param b: m dimensional numpy array, the starting vector :param k: integer, the number of iterations :return Q: an mx(k+1) dimensional numpy array containing the orthonormal basis :return H: a (k+1)xk dimensional numpy array containing the upper \ Hessenberg matrix """ raise NotImplementedError
[docs]def GMRES(A, b, maxit, tol, return_residual_norms=False, return_residuals=False): """ For a matrix A, solve Ax=b using the basic GMRES algorithm. :param A: an mxm numpy array :param b: m dimensional numpy array :param maxit: integer, the maximum number of iterations :param tol: floating point number, the tolerance for termination :param return_residual_norms: logical :param return_residuals: logical :return x: an m dimensional numpy array, the solution :return nits: if converged, the number of iterations required, otherwise \ equal to -1 :return rnorms: nits dimensional numpy array containing the norms of \ the residuals at each iteration :return r: mxnits dimensional numpy array, column k contains residual \ at iteration k """ raise NotImplementedError
[docs]def get_AA100(): """ Get the AA100 matrix. :return A: a 100x100 numpy array used in exercises 10. """ AA100 = np.fromfile('AA100.dat', sep=' ') AA100 = AA100.reshape((100, 100)) return AA100
[docs]def get_BB100(): """ Get the BB100 matrix. :return B: a 100x100 numpy array used in exercises 10. """ BB100 = np.fromfile('BB100.dat', sep=' ') BB100 = BB100.reshape((100, 100)) return BB100
[docs]def get_CC100(): """ Get the CC100 matrix. :return C: a 100x100 numpy array used in exercises 10. """ CC100 = np.fromfile('CC100.dat', sep=' ') CC100 = CC100.reshape((100, 100)) return CC100