Math 304, Homework 10 (Partial Differential Equations)

Math304, Homework 10 (Linear Systems)
1. Consider the linear systems
 






0
2
3
0
−5
−2 −2 −2
 −2 −4 −4  x =  4  and  −4 −4
3 x =  7 .
6
0 −4 −4
8
−2 −4 −6
| {z }
|
| {z }
|
{z
}
{z
}
A1
A2
b1
b2
(a) Compute the LU factorizations of A1 and A2 by hand.
(b) Exploiting the LU factorizations from part (a) solve the linear systems
A1 x = b1
and
A2 x = b2 .
2. Devise a variant of the algorithm to compute an LU factorization that reduces an invertible
n × n matrix A directly into an n × n diagonal matrix D (instead of an upper triangular matrix).
A matrix D is called diagonal if all of its entries, other than its diagonal entries djj , are zero. This
process is commonly known as the Gauss-Jordan elimination. Describe the Gauss-Jordan matrices
Gi , i = 1, . . . , n involved in this process such that Gn . . . G1 A = D.
3. Recall that back substitution is the standard approach to solve the upper triangular linear
system
 



u11 u12 . . .
u1(n−1)
u1n
x1
b1

 

 0 u22
u2(n−1)
u2n 

  x2   b2 




 ..

.
.
.
.
..
..
..
..
=
.
 .

 



 0
u(n−1)(n−1) u(n−1)n   x(n−1)   b(n−1) 
xn
bn
0
0
unn
{z
} | {z }
{z
}|
|
U
x
b
(a) Implement back substitution in Matlab.Your matlab function must take two input parameters; an n × n (upper triangular) matrix U and a right-hand vector b ∈ Rn . It should return
one output parameter x ∈ Rn , which is the solution of U x = b. Your Matlab code should
look like
function x = backsubstitute(U,b)
n = length(b);
....
return;
In the above code you need to fill in the part in between the statements n = length(b); and
return;. Name your file as backsubstitute.m.
(b) Test your implementation in part (c) with the following upper triangular system

 


x1
−1
3
1
2
−9

 

 0 −1
3
1 

  x2  =  −3  .
 0
0 −1
3   x3   5 
−1
x4
0
0
0 −1
You can enter the coefficient matrix U above in Matlab by typing
U = [-1 3 1 2; 0 -1 3 1; 0 0 -1 3; 0 0 0 -1]
and the right-hand vector by typing
b = [-9; -3; 5; -1]
Compare the answer computed by your implementation with the answer returned by the
built-in linear system solver in Matlab. You can call your implementation by typing x =
backsubstitute(U,b) after entering U and b as suggested above. To use the built-in linear
system solver in Matlab type x = U\b.
4. Solve either Exercise 2.3 concerning a plane truss in Cleve Moler’s book available at
http://www.mathworks.com/moler/lu.pdf in Matlab, or the question below concerning a chemical
reaction.
(Gilat and Subramaniam, Problem 4.39) During the chemical reaction below the number of atoms
of each element (Cr, N, H, C, O, K, Mn, S) must be preserved.
(Cr(N2 H4 CO)6 )4 (Cr(CN )6 )3 + aKM nO4 + bH2 SO4 →
cK2 Cr2 O7 + dM nSO4 + eCO2 + f KN O3 + gK2 SO4 + hHO2
Set up a linear system involving the unknown coefficients a through h, and solve it in Matlab. To
solve the linear system Ax = b for x in Matlab, you should type x = A\b.
5. An n × n matrix T is called tridiagonal if tij = 0 for all i, j such that |i − j| > 1. Write down
a pseudocode computing an LU factorization for a tridiagonal matrix, and exploiting its special
structure. The number of flops your pseudocode requires must be O(n).