Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please answer within 12hrs I'll give u thumbs up. Q4. (GMRES and CG) Write a python code to do the following operations. 1. Define a

Please answer within 12hrs I'll give u thumbs up.
image text in transcribed
Q4. (GMRES and CG) Write a python code to do the following operations. 1. Define a function create_sparse_rand_matin, zero_trac) for creating 0 A: a sparse random symmetric matrix A of size Nx N with the fraction of non-zero elements zero_frac stored in format of compressed sparse row matrix (CSR), ) A_arr : 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.sparse.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 "4*np.eye(n) guaranttes that A is well-conditioned A-scipy.sparse.csr_matrix(A_arr) convert numpy array format to CSR format b- np.random. rand (1) 2. Create the matrice A in both CSR format and array format and b by caling the function create_sparse_rand_matin, zero_frac) 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_trac) defined in 04.1 with zero_trac =0.005. Count the times spent on runing scipy, sparse. linalg.gmres (a, b, xo, 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_trac) for creating 0 A: a sparse random symmetric matrix A of size Nx N with the fraction of non-zero elements zero_frac stored in format of compressed sparse row matrix (CSR), ) A_arr : 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.sparse.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 "4*np.eye(n) guaranttes that A is well-conditioned A-scipy.sparse.csr_matrix(A_arr) convert numpy array format to CSR format b- np.random. rand (1) 2. Create the matrice A in both CSR format and array format and b by caling the function create_sparse_rand_matin, zero_frac) 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_trac) defined in 04.1 with zero_trac =0.005. Count the times spent on runing scipy, sparse. linalg.gmres (a, b, xo, 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)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions