Question: In this exercise you are asked to implement in Python a randomized condition number estimator. The idea is that you start with a linear sytem
In this exercise you are asked to implement in Python a randomized condition number estimator. The idea is that you start with a linear sytem Ar=b whose solution you know explicitly. Given a matrix A you can do this for example by creating a vector e of all ones and computing b = Ae. You now define a small random perturbation 8A and solve the linear system (A+8A)(e+de) = b. An estimate for the relative condition number is now obtained as w(A) 1714. Based on this idea complete the following function to estimate the inf-norm condition number of a matrix A. -]: import numpy as np def condest(A, ntrials-5, eps 1E-15): ***Randomized estimation of condition numbers. Perform a random estimation of a condition number. The code solves ntrials linear systems with small normally distributed random perturbation matrices of size V\delta Altin) = eps and returns the maximum over all condition number estimates in these trials. # Delete the pass keyword and fill in the appropriate code. pass A - np.random. randn (100, 100) condition_estimate - condest (A) exact - np. linalg.cond(A, np.inf) # Note that the estimates and the exact condition number # can wildly quite a bit. What you are interested in, #1s getting the right magnitude. print("Estimated condition number: {condition_estimate") print("Exact condition number: (exact)) Show some experiments with different values for eps. In double precision what would be an appro priste value and what happens as eps becomes smaller? In this exercise you are asked to implement in Python a randomized condition number estimator. The idea is that you start with a linear sytem Ar=b whose solution you know explicitly. Given a matrix A you can do this for example by creating a vector e of all ones and computing b = Ae. You now define a small random perturbation 8A and solve the linear system (A+8A)(e+de) = b. An estimate for the relative condition number is now obtained as w(A) 1714. Based on this idea complete the following function to estimate the inf-norm condition number of a matrix A. -]: import numpy as np def condest(A, ntrials-5, eps 1E-15): ***Randomized estimation of condition numbers. Perform a random estimation of a condition number. The code solves ntrials linear systems with small normally distributed random perturbation matrices of size V\delta Altin) = eps and returns the maximum over all condition number estimates in these trials. # Delete the pass keyword and fill in the appropriate code. pass A - np.random. randn (100, 100) condition_estimate - condest (A) exact - np. linalg.cond(A, np.inf) # Note that the estimates and the exact condition number # can wildly quite a bit. What you are interested in, #1s getting the right magnitude. print("Estimated condition number: {condition_estimate") print("Exact condition number: (exact)) Show some experiments with different values for eps. In double precision what would be an appro priste value and what happens as eps becomes smaller
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
