Docsity

Solution to Linear Algebra Homework Problem: LU Decomposition and Matrix Condition Number , Assignments of Computer Science

Toggle sidebar
bg1
ME2016, Fall 2008, Dr. Ferri
Homework Assignment 6
Due Wednesday, October 8
Problem 1. (3 points)
Consider the system A*x = B:
⎪
⎪
⎪
⎭
⎪
⎪
⎪
⎬
⎫
⎪
⎪
⎪
⎩
⎪
⎪
⎪
⎨
⎧
=
⎪
⎪
⎪
⎭
⎪
⎪
⎪
⎬
⎫
⎪
⎪
⎪
⎩
⎪
⎪
⎪
⎨
⎧
⎥
⎥
⎥
⎥
⎥
⎥
⎦
⎤
⎢
⎢
⎢
⎢
⎢
⎢
⎣
⎡
2
5
4
7
8
11111
12112
11311
34542
54321
5
4
3
2
1
x
x
x
x
x
(a) Use the Matlab Command lu to find the matrices L, U, and P in the representation:
L*U = P*A
(b) Using L, U, and the permutation matrix P from part (a) perform the forward and back-
substitutions to obtain x. Show your steps.
Solution
(a) L,U,P returned by the Matlab function lu:
»A=[1 2 3 4 5; 2 4 5 4 3; 1 1 3 1 1 ; 2 1 1 2 1; 1 1 1 1 1 ];
»B=[8 7 4 5 2]';
»format rat % use rational fraction format
» [L,U,P]=lu(A)
Yields the following results:
L =
1 0 0 0 0
1 1 0 0 0
1/2 1/3 1 0 0
1/2 0 3/11 1 0
1/2 1/3 -1/11 -4/23 1
U =
2 4 5 4 3
0 -3 -4 -2 -2
0 0 11/6 -1/3 1/6
0 0 0 23/11 38/11
0 0 0 0 18/23
P =
0 1 0 0 0
0 0 0 1 0
0 0 1 0 0
1 0 0 0 0
0 0 0 0 1
Our objective is to solve A*x = B, using the fact that L*U = P*A. Pre-multiply both sides of A*x
= B by P. This yields
pf3
pf4
pf5

Partial preview of the text

Download Solution to Linear Algebra Homework Problem: LU Decomposition and Matrix Condition Number and more Assignments Computer Science in PDF only on Docsity!

ME2016, Fall 2008, Dr. Ferri Homework Assignment 6 Due Wednesday, October 8

Problem 1. (3 points) Consider the system A*x = B:

5

4

3

2

1

x

x

x

x

x

(a) Use the Matlab Command lu to find the matrices L, U, and P in the representation:

LU = PA

(b) Using L, U, and the permutation matrix P from part (a) perform the forward and back- substitutions to obtain x. Show your steps.

Solution (a) L,U,P returned by the Matlab function lu :

»A=[1 2 3 4 5; 2 4 5 4 3; 1 1 3 1 1 ; 2 1 1 2 1; 1 1 1 1 1 ]; »B=[8 7 4 5 2]'; »format rat % use rational fraction format » [L,U,P]=lu(A)

Yields the following results:

L = 1 0 0 0 0 1 1 0 0 0 1/2 1/3 1 0 0 1/2 0 3/11 1 0 1/2 1/3 -1/11 -4/23 1

U = 2 4 5 4 3 0 -3 -4 -2 - 0 0 11/6 -1/3 1/ 0 0 0 23/11 38/ 0 0 0 0 18/

P = 0 1 0 0 0 0 0 0 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 1

Our objective is to solve Ax = B, using the fact that LU = PA. Pre-multiply both sides of Ax = B by P. This yields

PAx PB LUx P B

Defining d = Ux, we must first solve Ld = P*B

5

4

3

2

1

d

d

d

d

d

Solving by forward-substitution, d 1 = 7, d 2 = -2, d 3 = 7/6, d 4 = 46/11, and d 5 = 0. Now, obtain x from the solution of U*x = d:

5

4

3

2

1

x

x

x

x

x

Solving by back-substitution, x 1 = 1, x 2 = -2, x 3 = 1, x 4 = 2, and x 5 = 0.

Problem 2. (3 points) Using the free-body diagrams of Figure P12.34, the following system of equations are stated in Problem 12.34 in the text: 100 a + T = 519. 72 50 a − T + R = 216. 55 25 a − R = 108. 27

(a) Find the LU decomposition for the coefficient matrix of the solution vector x = [ a T R ]T^. (b) Solve for x. Show all of your steps. (c) Show that, if the solution vector was ordered as vector x = [ R T a ]T, pivoting would become necessary. What would the permutation matrix [P] be for this case?

Solution (a) For the given order of x the equations can be written as:

If the process was continued, it would be found that no other row-pivots are necessary. Thus, the permutation matrix would consist of the 3x3 identity matrix, with the first and

second rows switched: ⎥

P

Problem 3. (4 points)

Consider the system [A]*x = B, where [A] is the NxN matrix having elements

  • − 1

i j

ij a (^) ij , and

B is the Nx1 vector [1 1 … 1]T. (The matrix A is similar to the Hilbert matrix discussed in example problem 10.4) It can be shown that the exact solution to this problem is x 1 =1, and x 2 = x 3

= x 4 = … = xN = 0. Note that [A] and B can be easily entered into Matlab with the commands:

A=zeros(N,N); for i=1:N; for j=1:N; A(i,j)=i*j/(i+j-1); end; end B=ones(N,1);

(a) For N = 3, solve for x using the Matlab "slash" command: x=A\B (type 'help slash' for further information.). Then, modify the elements of the vector B by very small random perturbations B_prime = B + 0.001*(rand(N,1)-0.5);

Re-solve for the solution using xp = A\B_prime and compare the two solutions x and xp (b) Repeat the calculations of part (a) using N=10. (c) Make a plot that shows the base-10 log of the matrix condition number (calculated using the Matlab command C=cond(A)) as a function of N as N is varied from 1 to 10. The easiest way to accomplish this task is to write a Matlab program (or script) that increments N (in a ‘ for loop ’, for example). For each value of N, the program needs to create a new NxN A matrix, calculate its condition number, and store the result in a vector.

Solution (a) N = 3

3

2

1

x

x

x

Solution of these equations gives identically , x = [1 0 0]T. Now, perturb the vector B

» B_prime = B + 0.001*(rand(N,1)-0.5) » xp=A\B_prime

B_prime =

xp =

-0.

We see that xp is very close to x = [1 0 0 ]T.

(b) N = 10

Using the same code as above, but with N = 10, yields x = A\B = [1 0 0 0 0 0 0 0 0 0]T. Now, perturb the vector B

» B_prime = B + 0.001*(rand(N,1)-0.5) » xp=A\B_prime

B_prime =

» xp xp =

1.0e+007 * -0.

-0.

-0.

-3.

-1.

We see that even though B_prime is very, very close to B, xp is now significantly different than x. For example, xp(1) = -666.40 instead of x(1) = 1. The largest element of xp, in fact, is xp(7) = -3.140754619e+007 which is radically different than x(7) = 0. In general, we know that

B

B

cond(A) x

Δ x Δ

Using the N=10 example, the right-hand-side can be evaluated as:

» rhs = cond(A)*norm(B_prime-B)/norm(B)

rhs = 1.453523675267285e+