Exercises 7.9 - 7.11

9 minute read

Chapter 7. Dimension and Structure

7.9 Orthonormal Bases and the Gram Schmidt Process

Exercise 7.12 (Gram-Schmidt Process)

Perform the Gram-Schmidt process to transform the vectors given in the Example 9 of the Section 7.9 to obtain an orthonormal basis for \(\mathbb{R}^{3}\).
In this problem, use a nested loop and the MATLAB command norm.

Solution

w1 = [1 1 1]'; w2 = [0 1 1]'; w3 = [0 0 1]';
A = [w1 w2 w3]; % Construct a matrix A whose columns are w1, w2, and w3.
format short; [m, n] = size(A);
Q = zeros(m, n); % Initialize the matrix Q as an m*n zero matrix.

% Find an orthonormal basis for the column space of A.
for j = 1 : n
    v = A(:, j); % v begins as jth column of A.
    for i = 1 : (j-1)
        temp = Q(:, i)' * A(:, j);
        % Subtract each component of orthogonal projection of v
        % onto the subspace spanned by the vector Q(:, i).
        v = v - temp * Q(:, i);
    end
    Q(:, j) = v / norm(v); % Normalize v by its 2-norm.
end
disp('The orthonormal basis {q1,q2,q3} for R^3 from {w1,w2,w3} are as follows:')
disp('q1='); disp(Q(:,1)'); disp('q2='); disp(Q(:,2)'); disp('q3='); disp(Q(:,3)');

MATLAB results

The orthonormal basis {q1,q2,q3} for R^3 from {w1,w2,w3} are as follows:
q1=
    0.5774    0.5774    0.5774

q2=
   -0.8165    0.4082    0.4082

q3=
   -0.0000   -0.7071    0.7071

Exercise 7.13 (Orthonormal Bases for the Four Fundamental Spaces)

Find orthonormal bases for the four fundamental spaces of the matrix

\[A = \left[\begin{array}{rrrr} 2& \hspace{2mm} -1& \hspace{5mm} 3&\hspace{4mm} 5\\ 4 & -3 & 1 & 3 \\ 3 & -2 & 3 & 4 \\ 4 & -1 & 15 & 17 \\ 7 & -6 & -7 & 0 \end{array} \right].\]
%--- The following is the function file 'GramSchmidt.m'. ---%

% Find an orthonormal basis for col(A) when A has full column rank.
function Q = GramSchmidt(A)

[m, n] = size(A);

% Initialize the matrix Q as an m*n zero matrix.
Q = zeros(m, n);

for j = 1 : n
    % v begins as jth column of A.
    v = A(:, j);
    for i = 1 : (j-1)
        temp = Q(:, i)' * A(:, j);
        % Subtract each component of orthogonal projection of v
        % onto the subspace spanned by the vector Q(:, i).
        v = v - temp * Q(:, i);
    end
    Q(:, j) = v / norm(v); % Normalize v by its 2-norm.
end
end
% Q is an m*n matrix whose columns form an orthonormal basis for col(A).

The following commands are performed in the command window of MATLAB.

Solution

A = [2 -1 3 5; 4 -3 1 3; 3 -2 3 4; 4 -1 15 17; 7 -6 -7 0];
format short;

% Find the reduced row echelon form of A.
rref_A = rref(A);

% (1). Find an orthonormal basis for the row space of A.
% From the result of rref_A, the first three nonzero rows in rref_A form
% a basis for the row space of A.

% Construct a matrix R_A whose columns are a basis for the row space of A.
R_A = rref_A(1:3, :)';

% Find an orthonormal basis for the column space of R_A by Gram-Schmidt process,
% which is the same as finding an orthonormal basis for the row space of A.
Orth_R_A = GramSchmidt(R_A);

a1 = Orth_R_A(:, 1); a2 = Orth_R_A(:, 2); a3 = Orth_R_A(:, 3);

disp('An orthonormal basis {a1, a2, a3} for the row space of A is');
disp('a1 = '); disp(a1'); disp('a2 = '); disp(a2'); disp('a3 = '); disp(a3');

% (2). Find an orthonormal basis for the column space of A.
% From the result of rref_A, the first three columns of A are the pivot columns
% which form a basis for the column space of A.

% Construct a matrix C_A whose columns are a basis for the column space of A.
C_A = A(:, 1:3);

% Find an orthonormal basis for the column space of C_A by Gram-Schmidt process,
% which is the same as finding an orthonormal basis for the column space of A.
Orth_C_A = GramSchmidt(C_A);

b1 = Orth_C_A(:, 1); b2 = Orth_C_A(:, 2); b3 = Orth_C_A(:, 3);

disp('An orthonormal basis {b1, b2, b3} for the column space of A is');
disp('b1 = '); disp(b1'); disp('b2 = '); disp(b2'); disp('b3 = '); disp(b3');


% (3). Find an orthonormal basis for the null space of A.
% In addition, from the result of rref_A,
% we can easily see that {[-6 -7 0 1]'} is a basis for N(A).

% Construct a matrix N_A whose columns are a basis for the null space of A.
N_A = [-6 -7 0 1]';

% Find an orthonormal basis for the column space of N_A by Gram-Schmidt process,
% which is the same as finding an orthonormal basis for the null space of A.
Orth_N_A = GramSchmidt(N_A);

c1 = Orth_N_A(:, 1);
disp('An orthonormal basis {c1} for the null space of A is');
disp('c1 = '); disp(c1');

% (4). Find an orthonormal basis for the null space of A transpose.
[L, U, P] = lu(A);
temp = [0 0 0 0 1]';
% Make L a square matrix of order 5.
L = [L temp];

% Make U have the same size of A.
U(5, :) = 0;

% Then, we have P*A = L*U, which is the same result as above.
% Note that L^(-1)*P*A = U, where U is an upper triangular matrix.

E = L^(-1)*P;

% Since E = L^(-1)*P is a product of elementary matrices s.t. E*A=U,
% E represents a set of elementary row operations
% that makes A become a row echelon form U.

% ref_par_A is the resulting partitioned matrix [U E].
ref_par_A = [U E];

% From the result of ref_par_A, we can see that ref_par_A([4:5], [1:4]) = 0.
% Thus, the row vectors of E2 form a basis for null(A'),
% where E2 = ref_par_A([4:5], [5:9]).

% Construct a matrix N_Atrans whose columns are a basis for
% the null space of A transpose.
N_Atrans = ref_par_A(4:5, 5:9)';

% Find an orthonormal basis for the column space of N_Atrans by Gram-Schmidt process,
% which is the same as finding an orthonormal basis for the null space of A transpose.
Orth_N_Atrans = GramSchmidt(N_Atrans);

d1 = Orth_N_Atrans(:, 1); d2 = Orth_N_Atrans(:, 2);
disp('An orthonormal basis {d1, d2} for the null space of the transpose of A is');
disp('d1 = '); disp(d1'); disp('d2 = '); disp(d2');

MATLAB results

An orthonormal basis {a1, a2, a3} for the row space of A is
a1 = 
    0.1644         0         0    0.9864

a2 = 
   -0.7446    0.6559         0    0.1241

a3 = 
     0     0     1     0

An orthonormal basis {b1, b2, b3} for the column space of A is
b1 = 
    0.2063    0.4126    0.3094    0.4126    0.7220

b2 = 
    0.1873   -0.0887    0.0493    0.8378   -0.5027

b3 = 
   -0.3699    0.5812    0.5878   -0.1321   -0.4029

An orthonormal basis {c1} for the null space of A is
c1 = 
   -0.6470   -0.7548         0    0.1078

An orthonormal basis {d1, d2} for the null space of the transpose of A is
d1 = 
         0   -0.6758    0.7278   -0.0520    0.1040

d2 = 
    0.8863    0.1653    0.1629   -0.3282   -0.2300

7.10 \(QR-\)Decomposition; Householder Transformations

Exercise 7.14 (\(QR-\)Decomposition)

  1. Make a function file myQR.m to find a \(QR\)-decomposition of a given matrix. You may use your function file GS_process.m from the Exercise 7.13.

  2. For a given matrix,

    \[A=\begin{bmatrix} 1 & 1 & 1\\ 1& 0 & 2\\ 0 & 1& 2\end{bmatrix}.\]

    Compare your result with the output produced by the MATLAB command qr.

Solution

  1. myQR function
     %--- This is a function file myQR.m ---%
    
     function [Q, R]=myQR(A)
         Q = GS_process(A);
         R = Q'*A;
     end
    
  2. A=[1 1 1; 1 0 2; 0 1 2];
    [Q1, R1]=myQR(A); [Q, R]=qr(A);
    
    disp('my QR result'); disp('Q');disp(Q1); disp('R');disp(R1);
    disp('MATLAB QR result'); disp('Q');disp(Q); disp('R');disp(R);
    

MATLAB results

my QR result
Q
    0.7071    0.4082   -0.5774
    0.7071   -0.4082    0.5774
         0    0.8165    0.5774

R
    1.4142    0.7071    2.1213
    0.0000    1.2247    1.2247
    0.0000   -0.0000    1.7321

MATLAB QR result
Q
   -0.7071    0.4082   -0.5774
   -0.7071   -0.4082    0.5774
         0    0.8165    0.5774

R
   -1.4142   -0.7071   -2.1213
         0    1.2247    1.2247
         0         0    1.7321

The results are the same.

7.11 Coordinates with Respect to a Basis

Exercise 7.15 (Transition Matrices between Two Different Bases)

  1. Confirm that \(B_{1} = \{\mathbf{u}_{1}, \mathbf{u}_{2}, \mathbf{u}_{3}, \mathbf{u}_{4}, \mathbf{u}_{5}\}\) and \(B_{2} = \{\mathbf{v}_{1}, \mathbf{v}_{2}, \mathbf{v}_{3}, \mathbf{v}_{4}, \mathbf{v}_{5}\}\) are bases for \(\mathbb{R}^{5}\), and find the transition matrices \(P_{B_{1} \rightarrow B_{2}}\) and \(P_{B_{2} \rightarrow B_{1}}\), where

    \[\begin{array}{lllllll} \mathbf{u}_{1} & = & (3, \hspace{1mm} 1, \hspace{1mm} 3, \hspace{1mm} 2, \hspace{1mm} 6) & \hspace{4mm} & \mathbf{v}_{1} & = & (2, \hspace{1mm} 6, \hspace{1mm} 3, \hspace{1mm} 4, \hspace{1mm} 2) \\ \mathbf{u}_{2} & = & (4, \hspace{1mm} 5, \hspace{1mm} 7, \hspace{1mm} 2, \hspace{1mm} 4) & \hspace{4mm} & \mathbf{v}_{2} & = & (3, \hspace{1mm} 1, \hspace{1mm} 5, \hspace{1mm} 8, \hspace{1mm} 3) \\ \mathbf{u}_{3} & = & (3, \hspace{1mm} 2, \hspace{1mm} 1, \hspace{1mm} 5, \hspace{1mm} 4) & \hspace{4mm} & \mathbf{v}_{3} & = & (5, \hspace{1mm} 1, \hspace{1mm} 2, \hspace{1mm} 6, \hspace{1mm} 7) \\ \mathbf{u}_{4} & = & (2, \hspace{1mm} 9, \hspace{1mm} 1, \hspace{1mm} 4, \hspace{1mm} 4) & \hspace{4mm} & \mathbf{v}_{4} & = & (8, \hspace{1mm} 4, \hspace{1mm} 3, \hspace{1mm} 2, \hspace{1mm} 6) \\ \mathbf{u}_{5} & = & (3, \hspace{1mm} 3, \hspace{1mm} 6, \hspace{1mm} 6, \hspace{1mm} 7) & \hspace{4mm} & \mathbf{v}_{5} & = & (5, \hspace{1mm} 5, \hspace{1mm} 6, \hspace{1mm} 3, \hspace{1mm} 4) \\ \end{array}\]
  2. Find the coordinate matrices with respect to \(B_{1}\) and \(B_{2}\) of \(\mathbf{w} = (1, \hspace{1mm} 1, \hspace{1mm} 1, \hspace{1mm} 1, \hspace{1mm} 1)\).

Solution

u1 = [3 1 3 2 6]'; v1 = [2 6 3 4 2]';
u2 = [4 5 7 2 4]'; v2 = [3 1 5 8 3]';
u3 = [3 2 1 5 4]'; v3 = [5 1 2 6 7]';
u4 = [2 9 1 4 4]'; v4 = [8 4 3 2 6]';
u5 = [3 3 6 6 7]'; v5 = [5 5 6 3 4]';

U = [u1 u2 u3 u4 u5];
V = [v1 v2 v3 v4 v5];

format short;

% Initialization.
P_B1B2 = zeros(5);
P_B2B1 = zeros(5);

for j = 1:5
    % Find the coordinate vector of U(:, j) in B1 with respect to B2.
    P_B1B2(:, j) = V\U(:, j);
    % Find the coordinate vector of V(:, j) in B2 with respect to B1.
    P_B2B1(:, j) = U\V(:, j);
end

disp('The transition matrix from B1 to B2 is'); disp(P_B1B2);
disp('The transition matrix from B2 to B1 is'); disp(P_B2B1);

w = [1 1 1 1 1]';

% Find the coordinate matrix of w with respect to B1.
w_B1 = U\w;

% Find the coordinate matrix of w with respect to B2.
w_B2 = P_B1B2 * w_B1;

disp('The coordinate matrix of w with respect to B1 is'); disp(w_B1');
disp('The coordinate matrix of w with respect to B2 is'); disp(w_B2');

MATLAB results

    The transition matrix from B1 to B2 is
       -0.4992   -0.2531    0.4843    1.8286   -0.2123
       -0.7830   -0.3679    0.1604   -0.8019   -0.5849
        1.3019    0.2925    0.4623    0.6887    1.4906
       -0.9096   -0.6116    0.1918   -0.2091   -1.4104
        1.4230    1.8082   -0.4591   -0.2044    1.8019

    The transition matrix from B2 to B1 is
       -0.6889   -1.3556    0.6222    1.2667   -0.0444
        0.4067    0.3591    0.0278    1.2083    1.0873
        0.3151    1.2675    1.3444    1.6833    0.6540
        0.3615   -0.5433   -0.2056   -0.1417   -0.0746
        0.2571    0.9714   -0.2000   -1.8000   -0.3429

    The coordinate matrix of w with respect to B1 is
       -0.0222    0.1508    0.1841   -0.0016   -0.0286

    The coordinate matrix of w with respect to B2 is
        0.0653    0.0094    0.0566    0.0039    0.1053

Leave a comment