Q4. (GMRES and CG) Write a python code to do the following operations. 1. Define a function create_sparse_rand_matin, zero_frac) for creating (0) A: a sparse random symmetric matrix A of size N x N with the traction of non-zero elements zero_trac stored in format of compressed sparse row matrix (CSR), M) Aare: the same matrix A stored in format of numpy array, and I b: a random matrix b of size N x 1 by A-scipy.aparse.random(N, N, zero frac) sparse random matrix in format of CSR A - A.toarray() convert CSR format to numpy array format A arr - A+ np.transpose(A) + 4 np.eye() .addition of ***np.eye(n) guaranttes that A is well-conditioned Ascipy.sparse.csr_matrix(A_arr) convert numpy array format to CSR format b- np.random. rand (N, 1) 2. Create the matrice A in both CSR format and array format and b by caling the function create_sparse_rand_matin, zero_trac) defined in 04.1 with N = 100 and zero_trac = 0.005. Plot the matrix Athus created by innhow() in matplotib. 3. Loop over the matrix size N - 100, 150, 200,...,750,800. In each cycle with N, create random A and b by create_sparse_rand_matin, zero_frac) defined in 04.1 with zero_trac -0.005. Count the times spent on runing scipy sparse. linalg.gmres (A, b, x0, tol, maxiter). scipy.sparse. Linalg.cgi, b, xo, tol, maxiter) and acipy linalg.solve(a, b). The parameters are 0 = 0, tol = 10-10 and maxiter = 1000000. You can learn how to count the time by time.time_ns() in unit of nanosecond) from Page 13 of the note of lecture 2. For each cycle, append the values of N and the three times mentioned above to four lists. 4. Plot the computation times spent on three methods vs. N. Show the legend to label the meaning of each curve. (25 marks) Q4. (GMRES and CG) Write a python code to do the following operations. 1. Define a function create_sparse_rand_matin, zero_frac) for creating (0) A: a sparse random symmetric matrix A of size N x N with the traction of non-zero elements zero_trac stored in format of compressed sparse row matrix (CSR), M) Aare: the same matrix A stored in format of numpy array, and I b: a random matrix b of size N x 1 by A-scipy.aparse.random(N, N, zero frac) sparse random matrix in format of CSR A - A.toarray() convert CSR format to numpy array format A arr - A+ np.transpose(A) + 4 np.eye() .addition of ***np.eye(n) guaranttes that A is well-conditioned Ascipy.sparse.csr_matrix(A_arr) convert numpy array format to CSR format b- np.random. rand (N, 1) 2. Create the matrice A in both CSR format and array format and b by caling the function create_sparse_rand_matin, zero_trac) defined in 04.1 with N = 100 and zero_trac = 0.005. Plot the matrix Athus created by innhow() in matplotib. 3. Loop over the matrix size N - 100, 150, 200,...,750,800. In each cycle with N, create random A and b by create_sparse_rand_matin, zero_frac) defined in 04.1 with zero_trac -0.005. Count the times spent on runing scipy sparse. linalg.gmres (A, b, x0, tol, maxiter). scipy.sparse. Linalg.cgi, b, xo, tol, maxiter) and acipy linalg.solve(a, b). The parameters are 0 = 0, tol = 10-10 and maxiter = 1000000. You can learn how to count the time by time.time_ns() in unit of nanosecond) from Page 13 of the note of lecture 2. For each cycle, append the values of N and the three times mentioned above to four lists. 4. Plot the computation times spent on three methods vs. N. Show the legend to label the meaning of each curve. (25 marks)