Starting from:

$30

MTH 373/573 Homework 2 Solved

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.

More products