Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please please help me with python code for this problem. Problem which should be easy and estimate A i Write a routine for estimating the
Please please help me with python code for this problem.
Problem which should be easy and estimate A i Write a routine for estimating the condition number K A) of a matrix A using the IA- ,not compute it exactly (up to finite precision). One way to estimate A 1-norm. You will need to compute A Il is to choose a vector y such that the ratio Iy is large, where z is the solution to Az which is more challenging. Note that we only want to estimate y. Try two different approaches to choosing y: a Choose y as the solution to the system Ary-c, where c is a vector each of whose components is 1, with the sign for each component chosen by the following heuristic. Using the factorization A-LU, the system depending on AT CIS solved in two stages, successively solving the triangular systems UTV and y v. At each step ot the first triangular solution, choose the corresponding component of c to be either or which will make the resulting component of v larger in magnitude. (You will need to write a custom triangular solution routine to implement this.) Then solve the second triangular system in the usual way for y. The idea here is that any ill-conditioning in A will be reflected in U, resulting in a relatively large v. The relatively well-conditioned unit triangular matrix L will then preserve this relationship, resulting in a relatively large y b. Choose five different vectors y randomly and use the one producing the largest ratio llz/yll Test both the approaches described in parts (a) and (b) on each of the following two matrices -10 70 Ai=15-1 5 -3 2 6 92 66 25 A2-1-73 78 24 -80 37 10 Report your results using these two methods. Check the quality of your estimates using the function rp.linalg.condla,1) and report your results. For solving the linear system Ax = b, you can use the following code import numpy anp Note: The only place where you should not use this routine is when sclving the system Uvc, where you need to adjust each component of c depending on the magnitude of the correspanding component of v For computing the LU decomposition of a matrix A, you can use the following code Erom scipy-linalg inport 1u Both the matrices Ai and A2 have been chosen such that the permutation matrix Px, the identity matrix. So you do not need to worry about pivoting in this problem. Finally, to generate a random vector y using NumPy, you can use the following code np.random.rand3,1) arraytt 0.168231981, 0.91157363] 0.34R37631]1 Needless to say, you cannot use the function np.1inalg.norn in this problem to compute the norm of a matrix. However, you can (and should) use it to compute the norm of a vector. Please use double precision, which is the default precision in Python. Problem which should be easy and estimate A i Write a routine for estimating the condition number K A) of a matrix A using the IA- ,not compute it exactly (up to finite precision). One way to estimate A 1-norm. You will need to compute A Il is to choose a vector y such that the ratio Iy is large, where z is the solution to Az which is more challenging. Note that we only want to estimate y. Try two different approaches to choosing y: a Choose y as the solution to the system Ary-c, where c is a vector each of whose components is 1, with the sign for each component chosen by the following heuristic. Using the factorization A-LU, the system depending on AT CIS solved in two stages, successively solving the triangular systems UTV and y v. At each step ot the first triangular solution, choose the corresponding component of c to be either or which will make the resulting component of v larger in magnitude. (You will need to write a custom triangular solution routine to implement this.) Then solve the second triangular system in the usual way for y. The idea here is that any ill-conditioning in A will be reflected in U, resulting in a relatively large v. The relatively well-conditioned unit triangular matrix L will then preserve this relationship, resulting in a relatively large y b. Choose five different vectors y randomly and use the one producing the largest ratio llz/yll Test both the approaches described in parts (a) and (b) on each of the following two matrices -10 70 Ai=15-1 5 -3 2 6 92 66 25 A2-1-73 78 24 -80 37 10 Report your results using these two methods. Check the quality of your estimates using the function rp.linalg.condla,1) and report your results. For solving the linear system Ax = b, you can use the following code import numpy anp Note: The only place where you should not use this routine is when sclving the system Uvc, where you need to adjust each component of c depending on the magnitude of the correspanding component of v For computing the LU decomposition of a matrix A, you can use the following code Erom scipy-linalg inport 1u Both the matrices Ai and A2 have been chosen such that the permutation matrix Px, the identity matrix. So you do not need to worry about pivoting in this problem. Finally, to generate a random vector y using NumPy, you can use the following code np.random.rand3,1) arraytt 0.168231981, 0.91157363] 0.34R37631]1 Needless to say, you cannot use the function np.1inalg.norn in this problem to compute the norm of a matrix. However, you can (and should) use it to compute the norm of a vector. Please use double precision, which is the default precision in PythonStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started