100% Guaranteed Results


18-330 – Exercise 1: LU factorization Solved
$ 29.99
Category:

Description

5/5 – (1 vote)

Suppos you are given an upper-triangular ๐‘š ร— ๐‘š matrix U, i.e. all elements below the main diagonal are known to be 0. We wish to solve Ux = b for the vector x.
1. Find the analytical solution for the components ๐‘ฅ๐‘– of x in terms of the ๐‘ˆ๐‘–,๐‘— and ๐‘๐‘– using backsubstitution. (Hint: Where should you start?)
2. Write a function backsubstitution(U, b) that implements this.
3. What is the approximate operation count to perform backsubstitution?
4. Repeat [1]โ€“[3] for forward substitution to solve Lx = b for a lowertriangular matrix L.
5. Write down what happens at a general step in the Gaussian elimination process for a matrix ๐ด, in terms of the old coefficients ๐ด๐‘–,๐‘— and the new coefficients ๐ดโ€ฒ๐‘–,๐‘—.
6. Implement Gaussian elimination for an ๐‘š ร— ๐‘š square matrix ๐ด to calculate the ๐ฟ๐‘ˆ factorization without pivoting. Your function LU_factorization should return L and U.
7. What is the operation count of this algorithm?
8. Write a function solve_linear_system(A, b) that uses the functions you have written to solve the linear system Ax = b.
9. Consider the matrix A built by the following Julia code. Please use exactly this code so that the results are consistent:
using Random
rng = MersenneTwister(1234) A = randn(rng, Float64, (10, 10)) b = randn(rng, Float64, 10) Solve Ax = b for this A and b.
Print out the full x vector using jl show(stdout, “text/plain”, x) (This prevents the ellipses, …, that can occur in compressed output.)
Compare this to the result from Juliaโ€™s (backslash) operator and comment.
10. Find the size of the residual Ax โˆ’ b using the maximum norm (i.e. find the largest entry of the vector) for the x you found using your solve_linear_system(A, b) function.
11. Plot the residual as a function of ๐‘š for matrices of sizes between ๐‘š = 10 and ๐‘š = 1000 (or however high your computer can manage) on suitable axes.
How does the residual grow as the size grows?
Exercise 2: Exploiting structure in matrices 1 : Banded LU
In this exercise we will exploit structure in a matrix, i.e. the location of zero elements. If we know in advance that there are zeros in a certain part of the matrix (โ€œstructural zerosโ€), we can exploit that information to define more efficient operations on matrices of that type.
๐ด๐‘–๐‘— โ‰  0 โŸน ๐‘– โˆ’ ๐‘ โ‰ค ๐‘— โ‰ค ๐‘– + ๐‘ž
For example, a diagonal matrix is (0,0)-banded (only the main diagonal is present) and a tridiagonal matrix is (1,1)-banded.
As an example, think of a system of ๐‘› particles in a line, each of which interacts only with its nearest neighbour on each side. This could lead to an interaction matrix that is known in advance to be tridiagonal, hence leading to the possibility of more efficiently solving the dynamics. Finite difference matrices are also banded. The matrices without structure that we discussed in the lectures on LU and QR are called dense matrices. We will define a new type Banded as follows:
struct Banded{T} <: AbstractMatrix{T} bands::Matrix{T} p::Int q::Int
end
Here, bands is a matrix that stores only the bands (diagonals) of the original matrix, numbered (โˆ’๐‘,โˆ’(๐‘โˆ’1),โ€ฆ,0,1,โ€ฆ๐‘ž), where 0 corresponds to the main diagonal.
Note that there are more terms in bands than we need to store. We will store the lower bands justified to the bottom and the upper bands justified to the top. For example, consider the general (3, 2) banded matrix, i.e. with 3 diagonals below and 2 diagonals above the main diagonal.
๐‘11 ๐‘12 ๐‘13
โŽก๐‘21 ๐‘22 ๐‘23 โŽข๐‘31 ๐‘32 ๐‘33
๐ต = โŽข๐‘41 ๐‘42 ๐‘43 โŽข ๐‘52 ๐‘53
โŽฃ ๐‘63
This would be stored as follows in bands: ๐‘24
๐‘34
๐‘44
๐‘54
๐‘64 ๐‘35
๐‘45
๐‘55
๐‘65 โŽค
โŽฅ
๐‘46โŽฅโŽฅ
๐‘56
๐‘66โŽฆ
๐‘41 ๐‘31 ๐‘21
โŽก๐‘52 ๐‘42 ๐‘32
๐ต = โŽขโŽข๐‘063 ๐‘๐‘6453 ๐‘๐‘5443
โŽข 0 0 ๐‘65
โŽฃ 0 0 0 ๐‘11
๐‘22
๐‘33
๐‘44
๐‘55 ๐‘66 0
๐‘12
๐‘23
๐‘34
๐‘45
๐‘56 0
0 โŽค
๐‘13โŽฅ
๐‘24โŽฅโŽฅ
๐‘35
๐‘46โŽฆ
The columns of the new matrix correspond to the diagonals of the old matrix.
Although this seems not to be more efficient in terms of storage, it will be for a larger matrix.
1. Write a function mymul(B::Banded, v::Vector) that returns the matrixโ€“ vector product B*v. The function should be optimized in the sense that terms we know are 0 are not calculated. Compare the result to the built-in dense matrix multiply using the code Array(B) * v. (Array(B) produces a dense matrix with the same bands as B).
2. Consider the LU factorization. Show, using the formula for matrix multiplication, that if ๐ฟ is (๐‘,0)-banded and ๐‘ˆ is (0,๐‘ž)-banded then A = LU is (๐‘,๐‘ž)-banded.
3. Now show, by thinking about how the elimination algorithm works, that if A is (๐‘,๐‘ž)-banded then the factor L is (๐‘,0)-banded and U is (0,๐‘ž)banded.
4. We have seen that the structure of bandedness is maintained during an LU factorization. We saw in Exercise 1 that the operation count for a dense LU factorization is ๐’ช(๐‘›3). What happens to the operation count when we exploit the banded structure of a (๐‘,๐‘ž)-banded matrix of size ๐‘š ร— ๐‘š? Find the approximate operation count in terms of ๐‘š, ๐‘ and ๐‘ž.
5. Implement LU factorization for a banded matrix, LU_factorization(B::Banded), making sure to operate only on non-zero entries.
6. Given the new operation count, is the naive back/forward substitution or the LU factorization the bottleneck when solving a banded system? If LU is no longer the bottleneck, add methods for your substitution functions so that they are specialized for banded matrices.
(Hint for parts 5 & 6: if you fully understand what is happening here, modifying your LU / substitution codes from Exercise 1 should be simple for banded matrices, changing at most 1 or two lines of code.)
7. As an example of how necessary it is to exploit structure for efficiency, create a random tridiagonal matrix A of size ๐‘› ร— ๐‘› and a random vector b of length ๐‘›, taking ๐‘› = 10,000 (or whatever your computer can safely handle. How many times faster does your structured LU code run than if you were to use dense (standard) linear algebra (after you convert your banded matrix to a dense matrix)? (Remember to run your code once before timing it.)
8. Check numerically the dependence on ๐‘š that you found in question [4] by solving random tridiagonal systems of sizes ๐‘šร—๐‘š for ๐‘š between 10 and 10,000 and plotting the time taken as a function of ๐‘š. (If the times are too fast, use larger values of ๐‘š!)
[You can use @elapsed (or @belapsed from BenchmarkTools.jl) to capture the time taken by a Julia operation, so that you can automate this in a loop.]
Exercise 3: Exploiting structure in matrices 2 : Tridiagonal QR
In this exercise we will see how to exploit structure (zeros again) to make a more efficient QR algorithm. (However, we do not ask you to code the algorithm this time.)
Consider a general tridiagonal matrix (i.e. a (1,1)-banded matrix):
๐‘1 ๐‘1
โŽก๐‘Ž2 ๐‘2 ๐‘2 โŽค
๐‘‡ = โŽขโŽข ๐‘Ž3 ๐‘โ‹ฑ3 ๐‘โ‹ฑ3 โ‹ฑ โŽฅโŽฅ
โŽข ๐‘Ž๐‘โˆ’1 ๐‘๐‘โˆ’1 ๐‘๐‘โˆ’1โŽฅ
โŽฃ ๐‘Ž๐‘ ๐‘๐‘ โŽฆ
Since there is only a single subdiagonal, it should be easier to make the matrix upper-triangular by operating on it.
1. Consider the following rotation matrix:
๐‘…(๐œƒ) = [cossin ๐œƒ๐œƒ โˆ’cossin๐œƒ๐œƒ]
How should you choose ๐œƒ so that
๐‘ ๐‘Ÿ
๐‘…(๐œƒ)[๐‘ž] = [0]
where ๐‘Ÿ2 = ๐‘2 + ๐‘ž2 ? 2. Consider the matrix
๐‘…(๐œƒ) 0 ๐‘ƒ0 = [ 0 ๐ผ๐‘โˆ’2]
where ๐ผ๐‘ is the ๐‘ ร—๐‘ identity matrix, and where ๐œƒ is chosen as above for the terms ๐‘ = ๐‘1 and ๐‘ž = ๐‘Ž2. What does the resulting matrix ๐ด1ฬƒ = ๐‘ƒ0๐ด look like? Show that the first column is now upper-triangular.
To be more concrete consider the matrix
1 4 0 0
โŽก2 1 3 0โŽค ๐‘€ = โŽข0 5 6 7โŽฅ.
โŽฃ0 0 1 2โŽฆ
Show the resulting matrix when you multiply by ๐‘ƒ0 โ€“ is it what you expected?
3. What matrix should you multiply ๐ด1ฬƒ by to make the second column uppertriangular? (Hint: it will have a similar structure to ๐‘ƒ0) Check that the first column is still upper triangular. Call this matrix ๐‘ƒ1. Multiply the result of ๐‘ƒ0๐‘€ by ๐‘ƒ1 and show the result.
4. Generalize to the rotation matrix that makes the ๐‘›th column of a tridiagonal matrix upper-triangular. Call this matrix ๐‘ƒ๐‘›โˆ’1. Show that ๐‘ƒ๐‘›โˆ’1 is orthogonal, i.e. ๐‘ƒ๐‘›๐‘ƒ๐‘›โŠค = ๐ผ.
5. We can now write a tridiagonal matrix ๐‘‡ in upper-triangular form by forming the product ๐‘ƒ๐‘โˆ’2๐‘ƒ๐‘โˆ’3 โ‹ฏ๐‘ƒ1๐‘ƒ0๐‘‡ . From the above we see that the result of this will be an upper-triangular matrix ๐‘….
Show that the product of orthogonal matrices is orthogonal, and hence that this procedure gives a QR decomposition of ๐‘‡ .
6. What is the approximate operation count for a full QR factorization on a dense matrix ๐ด?
7. What is the approximate operation count for this reduced tridiagonal QR?
8. Extra credit Implement this algorithm in an efficient way.

Reviews

There are no reviews yet.

Be the first to review “18-330 – Exercise 1: LU factorization Solved”

Your email address will not be published. Required fields are marked *

Related products