Exercises 3.7 - 4.2
Chapter 3. Systems of Linear Equations
3.7 Matrix Factorizations; \(LU\)-Decomposition
Exercise 3.6. (\(LU\)-decompositions)
In this problem, we find an \(LU\)-decomposition of \(A\), where \(A\) is given in the of the Section \(3.7\).
-
Find an \(LU\)-decomposition of \(A\) by following the procedure given in the Example \(2\).
-
Solve the linear system \(A \mathbf{x} = \mathbf{b}\) by using the \(LU\)-decomposition of \(A\) obtained in (1), where \(\textbf{b} = \left[\begin{array}{r} 0 \\ -2 \\ 1 \end{array} \right].\)
-
Tell what happens if you use the MATLAB command
lu
of \(A\). Explain why this result differs from the result in (1).
Problem 1.
A = [6 -2 0; 9 -1 1; 3 7 5]; % Set the matrix A.
format rat; % Display results as a rational form.
% Initialization of U and L.
U = A; L = eye(3);
% Multiply the first row by 1/6.
U(1,:)=(1/6)*U(1,:);
% L(1,1) is the inverse of 1/6.
L(1,1)=(1/6)^(-1);
% Add (-9) times the first to the second.
U(2,:)=((-9)*U(1,:))+U(2,:);
% L(2,1) is the negative of (-9).
L(2,1)=-(-9);
% Add (-3) times the first to the third.
U(3,:)=((-3)*U(1,:))+U(3,:);
% L(3,1) is the negative of (-3).
L(3,1)=-(-3);
% Multiply the second row by 1/2.
U(2,:)=(1/2)*U(2,:);
% L(2,2) is the inverse of 1/2.
L(2,2)=(1/2)^(-1);
% Add (-8) times the second to the third.
U(3,:)=((-8)*U(2,:))+U(3,:);
% L(3,2) is the negative of (-8).
L(3,2)=-(-8);
disp('A is'); disp(A);
disp('The Lower Triangular part L is'); disp(L);
disp('The Upper Triangular part U is'); disp(U);
disp('The product L*U is'); disp(L*U);
MATLAB results.
A is
6 -2 0
9 -1 1
3 7 5
The Lower Triangular part L is
6 0 0
9 2 0
3 8 1
The Upper Triangular part U is
1 -1/3 0
0 1 1/2
0 0 1
The product L*U is
6 -2 0
9 -1 1
3 7 5
Problem 2.
% Solve the linear system Ax=b
% by using the LU-decomposition obtained in the problem 1.
% First, let us solve L*y = b by forward substitution.
% Set the right-hand-side vector b.
b = [0 -2 1]';
% Initialization of the solution vector y.
y = zeros(3, 1);
y(1) = b(1) / L(1, 1);
y(2) = (b(2) - (L(2, 1)*y(1))) / L(2, 2);
y(3) = (b(3) - (L(3, 1)*y(1)) - (L(3, 2)*y(2))) / L(3, 3);
% Next, let us solve U*x = y by backward substitution.
x = zeros(3, 1); % Initialization of the solution vector x.
x(3) = y(3) / U(3, 3);
x(2) = (y(2) - (U(2, 3)*x(3))) / U(2, 2);
x(1) = (y(1) - (U(1, 3)*x(3)) - (U(1, 2)*x(2))) / U(1, 1);
disp('The solution to Ax=b by the LU-decomposition is'); disp(x');
MATLAB results.
The solution to Ax=b by the LU-decomposition is
-11/6 -11/2 9
Problem 3.
fprintf('Using MATLAB command lu\n');
% LU decomposition of A with a permutation matrix.
[L, U, P] = lu(A);
disp('Lower triangular part L is'); disp(L);
disp('Upper triangular part U is'); disp(U);
disp('The permutation matrix P is'); disp(P);
disp('PA='); disp(P*A); disp('LU='); disp(L*U);
MATLAB results.
Using MATLAB command lu
Lower triangular part L is
1 0 0
1/3 1 0
2/3 -2/11 1
Upper triangular part U is
9 -1 1
0 22/3 14/3
0 0 2/11
The permutation matrix P is
0 1 0
0 0 1
1 0 0
PA=
9 -1 1
3 7 5
6 -2 0
LU=
9 -1 1
3 7 5
6 -2 0
Exercise 3.7. (\(LU\)-decomposition)
-
The MATLAB command
lu
is used to find the \(LU\)-decomposition of a matrix \(A\). Tell what happens if you use the commandlu
for \(A\), where \(A\) is given in the Example 2 of the Section 3.7. Explain why this result differs from the result in the textbook. -
Using MATLAB, observe what happens when you try to find an \(LU\)-decomposition of a singular matrix.
Problem 1.
% Construct the matrix A.
A=[6 -2 0; 9 -1 1; 3 7 5];
% LU decomposition of A.
[L, U, P]=lu(A);
disp('[L U P]=lu(A)');
disp('L'); disp(L); disp('U'); disp(U); disp('P'); disp(P);
MATLAB results.
[L U P]=lu(A)
L
1 0 0
1/3 1 0
2/3 -2/11 1
U
9 -1 1
0 22/3 14/3
0 0 2/11
P
0 1 0
0 0 1
1 0 0
Problem 2.
% Construct the some singular matrices.
A1=[1 0 0; -2 0 0; 4 6 1];
A2=[1 -2 7; -4 8 5; 2 -4 3];
A3=[1 0 0; -2 0 0; 4 6 1];
% LU decompositions of them.
[L1 U1 P1]=lu(A1); [L2 U2 P2]=lu(A2); [L3 U3 P3]=lu(A3);
disp('[L1 U1 P1]=lu(A1)'); disp('L1');disp(L1);disp('U1');disp(U1);
disp('[L2 U2 P2]=lu(A2)'); disp('L2');disp(L2); disp('U2');disp(U2);
disp('[L3 U3 P3]=lu(A3)'); disp('L3');disp(L3); disp('U3');disp(U3);
MATLAB results.
[L1 U1 P1]=lu(A1)
L1
1 0 0
-1/2 1 0
1/4 -1/2 1
U1
4 6 1
0 3 1/2
0 0 0
[L2 U2 P2]=lu(A2)
L2
1 0 0
-1/4 1 0
-1/2 0 1
U2
-4 8 5
0 0 33/4
0 0 11/2
[L3 U3 P3]=lu(A3)
L3
1 0 0
-1/2 1 0
1/4 -1/2 1
U3
4 6 1
0 3 1/2
0 0 0
Remark on problem 1. Since the permutation matrix \(P\) is not the identity matrix, the MATLAB command lu
gave us an \(LU\)-decomposition after multiplying \(A\) by the permutation matrix \(P\), hence, this decomposition is a \(PLU\)-decomposition of \(A\) because \(PA=LU\). Since at least one row interchange of \(A\) occurred in the process of \(LU\)-decomposition, this result is different from the decomposition result in the textbook.
Remark on problem 2. When we try \(LU\)-decomposition of the sigular matrices using the MATLAB command lu
, the resulting upper triangular matrices are singular.
Chapter 4. Determinants
4.1 Determinants; cofactor Expansion
Exercise 4.1.
Compute the determinants of the matrix A:
\[A = \begin{bmatrix} -4 & 1 & 1 & 1 & 1 & \\ 1 & -4 & 1 & 1 & 1 \\ 1 & 1 & -4 & 1 & 1 \\ 1 & 1 & 1 & -4 & 1 \\ 1 & 1 & 1 & 1 & -4 \end{bmatrix}.\]How can you construct \(A\) brilliantly?
Solution.
A = ones(5) - 5 * eye(5);
disp('A is'); disp(A);
disp('Determinant of A is'); disp(det(A));
MATLAB results.
A is
-4 1 1 1 1
1 -4 1 1 1
1 1 -4 1 1
1 1 1 -4 1
1 1 1 1 -4
Determinant of A is
0
Exercise 4.2.
Show that
\[\det \left( \begin{bmatrix} \displaystyle a & b & c & d \\ -b & a & d & -c \\ -c & -d & a & b \\ -d & c & -b & a \end{bmatrix} \right) = (a^2+b^2+c^2+d^2)^2.\]Solution.
syms a b c d;
A = [a b c d; -b a d -c; -c -d a b; -d c -b a];
disp('Given matrix is'); disp(A);
disp('Determinant of the given matrix is');
disp(simplify(det(A)));
MATLAB results.
Given matrix is
[ a, b, c, d]
[-b, a, d, -c]
[-c, -d, a, b]
[-d, c, -b, a]
Determinant of the given matrix is
(a^2 + b^2 + c^2 + d^2)^2
Exercise 4.3.
The \(n\)th-order Fibonacci matrix [named for the Italian mathematician (circa 1170 - 1250)] is the \(n \times n\) matrix \(F_{n}\) that has \(1\)’s on the main diagonal, \(1\)’s along the diagonal immediately above the main diagonal, \(-1\)’s along the diagonal immediately below the main diagonal, and zeros everywhere else. Construct the sequence
\[\det(F_{1}), \,\det(F_{2}), \,\det(F_{3}), \,\cdots, \det(F_{7}).\]Make a conjecture about the relationship between a term in the sequence and its two immediate predecessors, and then use your conjecture to make a guess at \(\det(F_{8})\). Check your guess by calculating this number.
Solution.
% Construct the 10x10 Fibonacci matrix F.
N = 10; nOnes = ones(N, 1);
F = diag(nOnes) + diag(nOnes(1:N-1),1) - diag(nOnes(1:N-1),-1);
for n = 1:7 % n is from 1 to 7
Fn = F(1:n,1:n); % nxn Fibonacci matrix is selected from F.
disp(det(Fn));
end
MATLAB results.
1
2
3
5
8
13
21
The constructed sequence satisfies the relationship
\[\det(F_n)=\det(F_{n-1})+\det(F_{n-2}),\]for \(\det(F_1)=1\) and \(\det(F_2)=2\). From that, we may guess that \(\det(F_8)=34\). MATLAB gives us the same output value 34 as our guess.
Exercise 4.4.
Let \(A_{n}\) be the \(n \times n\) matrix that has \(2\)’s along the main diagonal, \(1\)’s along the diagonals immediately above and below the main diagonal, and zeros everywhere else. Make a conjecture about the relationship between \(n\) and \(\det(A_{n})\).
Solution.
format rat;
% Construct the 10x10 matrix A satisfying given conditions.
n = 10; nOnes = ones(n, 1);
A = 2*diag(nOnes) + diag(nOnes(1:n-1),1) + diag(nOnes(1:n-1),-1);
for i = 1:10 % i is from 1 to 10
Ai = A(1:i,1:i); % A_i matrix is selected from A.
disp(det(Ai));
end
MATLAB results.
2
3
4
5
6
7
8
9
10
11
From the outputs, we make a conjecture about the relationship between \(n\) and \(\det(A_{n})\) as follows:
\[\det(A_{n})=n+1.\]4.2 Properties of Determinants
Exercise 4.5. (Determinants with \(LU\)-decomposition)
In this problem, we find the determinant of the matrix \(A\) by using the \(LU\)-decomposition of \(A\), where
\[A = \begin{bmatrix} -2 & 2 & -4 & -6\\ -3 & 6 & 3 & -15 \\ 5 & -8 & -1 & 17 \\ 1 & 1 & 11 & 7 \end{bmatrix}.\]-
Compute the determinant of \(A\) directly by using the MATLAB command
det
for \(A\). -
Compute the determinant of \(A\) by using the MATLAB command
lu
for \(A\). Confirm that you get the same results.
Problem 1.
A = [-2 2 -4 -6; -3 6 3 -15; 5 -8 -1 17; 1 1 11 7];
det_A = det(A); % Find the determinant of A by using the command det.
disp('The determinant of A by direct use of the command det is');
disp(det_A);
MATLAB results.
The determinant of A by direct use of the command det is
24
Problem 2.
[L, U, P] = lu(A); % We have a PLU-decomposition of A. (i.e., PA=LU ).
% Since the determinant of a triangular matrix is
% just a product of diagonal entries,
det_L = prod(diag(L)); % The product of diagonal entries of L.
% Or, you may use the command det for L, directly. (i.e., det_L = det(L)).
det_U = prod(diag(U)); % The product of diagonal entries of U.
% Or, you may use the command det for U, directly. (i.e., det_U = det(U)).
% If you observe the permutation matrix P, you can see that
% P is an odd permutation. Thus, we have det(P) = -1.
det_P = -1;
% Or, you may use the command det for P, directly. (i.e., det_P = det(P)).
% Since PA = LU, det(P)*det(A) = det(L)*det(U).
det_A = det_P * det_L * det_U;
disp('The determinant of A by using the LU-decomposition is'); disp(det_A);
MATLAB results.
The determinant of A by using the LU-decomposition is
24
Exercise 4.6. (Effects of Elementary Row Operations on the Determinant)
Using the MATLAB command det
, confirm the formulas (a) - (c) in Theorem 4.2.2 of Section 4.2 for the matrix \(A\) given in the problem 31 of Exercise set 4.1.
Solution.
A = [3 3 0 5; 2 2 0 -2; 4 1 -3 0; 2 10 3 2];
% (a). Multiply the second row of A by 2 and call it A2.
% Initialize the matrix A2 as A.
A2 = A;
% Multiply the second row of A by 2.
A2(2,:) = 2*A(2,:);
disp('The determinant of A2 is'); disp(det(A2));
disp('2*det(A) = '); disp(2*det(A));
% (b). Interchange the rows 2 and 4 of A and call it A24.
% Initialize the matrix A24 as A.
A24 = A;
% Interchange the rows 2 and 4 of A.
A24(2, :) = A(4, :) ; A24(4, :) = A(2, :);
disp('The determinant of A24 is'); disp(det(A24));
disp('-det(A) = '); disp(-det(A));
% (c). Add 2 times row 3 to row 4 of A and call it A234.
% Initialize the matrix A234 as A.
A234 = A;
% Add 2 times row 3 of A to row 4.
A234(4, :) = 2 * A(3, :) + A(4, :);
disp('The determinant of A234 is'); disp(det(A234));
disp('det(A) = '); disp(det(A));
MATLAB results.
The determinant of A2 is
-480
2*det(A) =
-480.0000
The determinant of A24 is
240.0000
-det(A) =
240.0000
The determinant of A234 is
-240.0000
det(A) =
-240.0000
Exercise 4.7.
Use a determinant to show that if \(a, b, c,\) and \(d\) are not all zeros, then the vectors
\[\begin{align} \mathbf{v}_{1} &= (a,\, b,\, c,\, d)\\ \mathbf{v}_{2} &= (-b, a, d, -c)\\ \mathbf{v}_{3} &= (-c, -d, a, b)\\ \mathbf{v}_{4} &= (-d, c, -b, a) \end{align}\]are linearly independent.
Solution.
syms a b c d;
v1 = [a b c d];
v2 = [-b a d -c];
v3 = [-c -d a b];
v4 = [-d c -b a];
V = [v1; v2; v3; v4];
disp('det(V) is'); disp(simplify(det(V)));
MATLAB results.
det(V) is
(a^2 + b^2 + c^2 + d^2)^2
Leave a comment