Exercises 2.1 - 3.4

6 minute read

Chapter 2. Systems of Linear Equations

2.1 Introduction to Systems of Linear Equatios

No MATLAB problems in this section.

2.2 Solving Linear Systems by Row Reduction

Exercise 2.1. (Reduced Row Echelon Form with Pivot Columns and Ranks)

In MATLAB, there are several useful commands for matrices such as rref command which produces the reduced row echelon form together with the pivot columns, and rank command which gives the number of the leading \(1\)’s without finding its row echelon form. Find the reduced row echelon form, the pivot columns, and the rank of the matrix \(A\), where

\[A = \begin{bmatrix} 2 & -3 & 1 & 0 & 4 \\ 1 & 1 & 2 & 2 & 0 \\ 3 & 0 & -1 & 4 & 5 \\ 1 & 6 & 5 & 6 & -4 \end{bmatrix}\]
% Construct the matrix A.
A=[2 -3 1 0 4; 1 1 2 2 0; 3 0 -1 4 5; 1 6 5 6 -4]; 

% Display the format of each entry as a rational form
format rat; 

% Find the reduced row echelon form 
% and the pivot columns of the matrix A.
[rref_A, pivotcols] = rref(A);

% Find the rank of the matrix A.
rank_A = rank(A); 

disp('The reduced row echelon form is'); disp(rref_A);
disp('The pivot columns are'); disp(pivotcols);
disp('The number of the leading 1 is'); disp(rank_A);

MATLAB results.

The reduced row echelon form is
       1              0              0             17/13           3/2     
       0              1              0             11/13          -1/2     
       0              0              1             -1/13          -1/2     
       0              0              0              0              0       

The pivot columns are
       1              2              3       

The number of the leading 1 is
       3       

Exercise 2.2. (Linear Combinations)

Use the MATLAB command rref to express the vector \(\mathbf{b}=(-21, \hspace{1mm}-60, \hspace{1mm}-3, \hspace{1mm}108, \hspace{1mm}84)\) as a linear combination of \(\mathbf{v_{1}}\), \(\mathbf{v_{2}}\), and \(\mathbf{v_{3}}\) where \(\mathbf{v_{1}}=(1, \hspace{1mm} -1, \hspace{1mm}3, \hspace{1mm}11, \hspace{1mm}20)\), \(\mathbf{v_{2}}=(10, \hspace{1mm}5, \hspace{1mm}15, \hspace{1mm}20, \hspace{1mm}11)\), and \(\mathbf{v_{3}}=(3, \hspace{1mm}3, \hspace{1mm}4, \hspace{1mm}4, \hspace{1mm}9)\).

% Construct b as a column vector.
b = [-21 -60 -3 108 84]';
% Set v1, v2, v3 as column vectors. 
v1 = [1 -1 3 11 20]'; 
v2 = [10 5 15 20 11]'; 
v3 = [3 3 4 4 9]';
% Set a matrix A with column vectors v1, v2 and v3. 
A = [v1 v2 v3]; 
% Augmented matrix [A | b].
augA = [A b]; 
% Reduced row echelon form of augA.
rref_augA = rref(augA);
% Solution vector from rref_augA. 
x = rref_augA(1:3, 4); 

% Display the result as an integer form.
format rat; 
disp('b is a linear combination of x(1)*v1+x(2)*v2+x(3)*v3, where');
disp('x(1) ='); disp(x(1)); disp('x(2) ='); disp(x(2));
disp('x(3) ='); disp(x(3));

MATLAB results.

b is a linear combination of x(1)*v1+x(2)*v2+x(3)*v3, where
x(1) =
      12       

x(2) =
       3       

x(3) =
     -21   

Chapter 3. Matrices and Matrix Algebra

3.1 Operations on Matrices

No MATLAB problems in this section.

3.2 Inverses; Algebraic Properties of Matrices

Exercise 3.1.

In this problem, we compute \(A^{5} - 3A^{3} + 7A - 4I\) for the matrix \(A\), where

\[A = \begin{bmatrix} 1 & 2 & -3 & 0\\ 1 & 1 & -2 & 1\\ 2 & 1 & 3 & 4\\ -3 & 2 & 2 & -8 \end{bmatrix}.\]
  1. Using the syntax A^k which produces the \(k\)-th power of a square matrix and the command eye for the identity matrix, compute the above matrix polynomial.

  2. Using the command polyvalm, compute the above matrix polynomial.

  3. Tell what happens if you type the syntax A.^k.

Solution.

% Construct the matrix A.
A = [1 2 -3 0; 1 1 -2 1; 2 1 3 4; -3 2 2 -8]; 

% (a)
result_a = A^5 + (-3)*A^3 + 7*A + (-4)*eye(4);

% Display the matrix polynomial.
disp('The result of the matrix polynomial is');
disp(result_a) 

% (b)
% Coefficient of the matrix polynomial.
coeff_poly = [1 0 -3 0 7 -4]; 

% Evaluate the matrix polynomial of coefficient
% with coeff_poly vector with the input matrix A.
result_b = polyvalm(coeff_poly, A);

% Display the matrix polynomial.
disp('The result of the matrix polynomial is');
disp(result_b);

% (c)
disp('The result of A.^2 is'); disp(A.^2);
disp('The result of A.^3 is'); disp(A.^3);
disp('The result of A.^4 is'); disp(A.^4);

MATLAB results.

The result of the matrix polynomial is
         874       -1272         -39        3021
        2580       -2306        -723        7536
        5191       -4121       -2444       14563
      -16852       12539        5649      -46917

The result of the matrix polynomial is
         874       -1272         -39        3021
        2580       -2306        -723        7536
        5191       -4121       -2444       14563
      -16852       12539        5649      -46917

The result of A.^2 is
     1     4     9     0
     1     1     4     1
     4     1     9    16
     9     4     4    64

The result of A.^3 is
     1     8   -27     0
     1     1    -8     1
     8     1    27    64
   -27     8     8  -512

The result of A.^4 is
           1          16          81           0
           1           1          16           1
          16           1          81         256
          81          16          16        4096

From the results, we can see that the syntax A.^k produces the entrywise \(k\)-th powers of the matrix \(A\).

3.3 Elementary Matrices; A Method for Finding \(A^{-1}\)

Exercise 3.2.

In this problem, we solve the linear system \(A \mathbf{x} = \mathbf{b}\) by using matrix inversion, where

\[A = \begin{bmatrix} 3 & 3 & -4 & -3 \\ 0 & 6 & 1 & 1\\ 5 & 4 & 2 & 1 \\ 2 & 3 & 3 & 2 \end{bmatrix} \quad \mathrm{and} \quad \mathbf{b} = \begin{bmatrix} -2 \\ 3 \\ 5 \\ 1 \end{bmatrix}.\]
  1. Use the MATLAB command inv or the syntax A^(-1) to find the inverse of \(A\).

  2. Display the output matrix as a rational form, NOT decimally. You may use the command format.

  3. Using the result of (a), compute the solution of the linear system \(A \mathbf{x} = \mathbf{b}\) by taking \(\mathbf{x} = A^{-1} \mathbf{b}\).

Solution.

% Construct the matrix A and the right-hand-side vector b.
A = [3 3 -4 -3; 0 6 1 1; 5 4 2 1; 2 3 3 2]; 
b = [-2 3 5 1]'; 

% (a)
% Use the command inv.
Inv_A1 = inv(A); 

% Use the syntax A^(-1).
Inv_A2 = A^(-1); 

% (b)
format rat; 
disp('The result of the command inv is'); disp(Inv_A1);
disp('The result of the syntax A^(-1) is'); disp(Inv_A2);

% (c)
% Since A is invertible, the solution to Ax=b is x=A^(-1)*b.
x = Inv_A1 * b;
disp('The solution to Ax=b is x = A^(-1)*b'); disp(x');

MATLAB results.

The result of the command inv is
      -7              5             12            -19       
       3             -2             -5              8       
      41            -30            -69            111       
     -59             43             99           -159       

The result of the syntax A^(-1) is
      -7              5             12            -19       
       3             -2             -5              8       
      41            -30            -69            111       
     -59             43             99           -159       

The solution to Ax=b is x = A^(-1)*b
      70            -29           -406            583

3.4 Subspaces and Linear Independence

Exercise 3.3. (Sigma notation)

Compute the linear combination

\[\mathbf{v}=\sum_{j=1}^{25} c_{j}\mathbf{v}_{j}\]

for \(c_{j}=1/j\) and \(\mathbf{v}_{j}=(\sin j, \cos j).\)

Solution.

v=zeros(1,2);
for i=1:25
       v=v+(1/i)*[sin(i), cos(i)];
end
disp(v);

MATLAB results.

    1.0322    0.0553

Exercise 3.4.

Let \(\mathbf{v_{1}}=(4, 3, 2, 1)\), \(\mathbf{v_{2}}=(5, 1, 2, 4)\), \(\mathbf{v_{3}}=(7, 1, 5, 3)\), \(\mathbf{x}=(16, 5, 9, 8)\), and \(\mathbf{y}=(3, 1, 2, 7)\). Determine whether \(\mathbf{x}\) and \(\mathbf{y}\) lie in \(\textrm{span}\{\mathbf{v_{1}}, \mathbf{v_{2}}, \mathbf{v_{3}}\}\).

Solution.

% Construct v1, v2, v3, x, y
v1=[4 3 2 1]'; v2=[5 1 2 4]'; v3=[7 1 5 3]';
x=[16 5 9 8]'; y=[3 1 2 7]';

% Augmented matrices [v1|v2|v3|x] and [v1|v2|v3|y]
X=[v1 v2 v3 x];
Y=[v1 v2 v3 y];

disp('Reduced row echelon form of [v1 v2 v3 x] is');
disp(rref(X));
disp('Reduced row echelon form of [v1 v2 v3 y] is');
disp(rref(Y));

MATLAB results.

Reduced row echelon form of [v1 v2 v3 x] is
     1     0     0     1
     0     1     0     1
     0     0     1     1
     0     0     0     0

Reduced row echelon form of [v1 v2 v3 y] is
     1     0     0     0
     0     1     0     0
     0     0     1     0
     0     0     0     1      

Therefore, \(\mathbf{x}\) lies in \(\textrm{span}\{\mathbf{v_{1}}, \mathbf{v_{2}}, \mathbf{v_{3}}\}\) and \(\mathbf{y}\) does not lie in \(\textrm{span}\{\mathbf{v_{1}}, \mathbf{v_{2}}, \mathbf{v_{3}}\}\).

Leave a comment