$30
Problem1: ForwardSubstitutiononSteroids
Suppose we are given a linear system ๐ด๐ฅ = ๐, we say we can solve for ๐ฅ without inverting ๐ด when we mean we can use Gaussian elimination (with or without partial or full pivoting as appropriate) to compute ๐ฅ. For example, we can solve for ๐ฆ = ๐ด−1๐ต๐ฅ by first computing ๐ง = ๐ต๐ฅ and then solving for ๐ฆ using ๐ด๐ฆ = ๐ง. In case of triangular linear systems, such solution would involve use of forward and back substitutions.
Using this background, suppose you are given ๐ฟ, ๐พ ∈ โ๐×๐ which are both lower triangular matrices, and ๐ต ∈ โ๐×๐ any general matrix. Then, specify an algorithm for computing ๐ ∈ โ๐×๐ so that
๐ฟ๐๐พ = ๐ต.
Problem2: Gaussianeliminationandpartialpivoting
(a) Write a function to implement Gaussian elimination with no pivoting as in algorithm 1.
(b) Write a function to implement Gaussian elimination with partial pivoting as in algorithm 2.
(c) Test your code. For each of the examples as stated below, report the various measurements as below in a table. Use relative measurements as necessary, and 2-norm for all appropriate norms and condition numbers. You can use functions available from NumPy or SciPy for these purposes.
• The condition number (np.linalg.cond),
• the error from un-pivoted solve from your function in part (a),
• the residual from un-pivoted solve from your function in part (a),
• the error from partially-pivoted solve from your function in part (b),
• the residual from partially-pivoted solve from your function in part (b),
• the error from np.linalg.solve,
• the residual from np.linalg.solve.
Report if any of the solves fail. You should try to write your code so that it prints the above table automatically without user interaction.
For each matrix below, write 2 or 3 sentences on your observations with regard to conditioning, necessity of pivoting, and reasons for your observed results.
Use the following matrices of sizes ๐ = 10, 20, 30, 40 to test your code:
1. A random matrix of size ๐×๐ with entries uniformly sampled from [0, 1) (use np.random.randn).
2. The Hilbert matrix given by:
๐๐๐ = ๐ + ๐ − 1 (๐, ๐ = 1, … , ๐).
3. The matrix given by
โก 1
โข
โข−1
๐ด๐ = โขโข−1
โข โฎ โข
โฃ−1
1
−1
−1
1 −1
โฏ
โฏ
โฏ
โฑ
โฏ
1โค
1โฅโฅ
1โฅ
โฅ
โฎโฅ
โฅ 1โฆ
๐
For each case, let ๐ฅโ = [1 โฏ 1] ∈ โ๐ be the vector of all 1s of size ๐. Now, compute ๐ as the matrix-vector product ๐ด ๐ฅโ and solve the linear system ๐ด ๐ฅ = ๐.
Problem3: ScaledLinearSystems
A matrix ๐ด = [๐๐๐]๐×๐ is said to row equilibrated if it is scaled so that max |๐๐๐| = 1, 1 ≤ ๐ ≤ ๐. In solving a system of equations ๐ด๐ฅ = ๐, we can produce an equivalent system in which the matrix is row equilibrated by dividing the ๐th equation by max1≤๐≤๐ |๐๐๐|.
(a) Solve the system of equations:
โก1
โข2
โข
โฃ1
1
−1 2
2 × 109โค โก๐ฅ1โค โก1โค
109 โฅ โขโข๐ฅ2โฅโฅ = โขโข1โฅโฅ
โฅ
0 โฆ โฃ๐ฅ3โฆ โฃ1โฆ
by using Gaussian elimination with partial pivoting and the function you wrote for it in Problem 2.
(b) Solve the same problem but now changing the linear system into a row equilibrated one and using Gaussian elimination without partial pivoting. You can reuse the function you wrote in Problem 2. Are the answers the same? Why or why not?
(c) State your reasoning for the why or why not part in 2 to 4 sentences.