import matplotlib.pyplot as plt
import numpy as np

9.9. Linear Algebra Lab Solutions#

  1. Put \(A\) into RREF.

\[\begin{split} A = \begin{bmatrix} 1 & 1 & 1 & 2\\ 2 & 3 & 1 & 3\\ 1 & -1 & -2 & -11\\ \end{bmatrix} \end{split}\]

Solution:

# Let's set up the matrix and row operation functions
A = np.array([[1,1,1,2],[2,3,1,3],[1,-1,-2,-11]])

# Swap two rows
def swap(matrix, row1, row2):
    copy_matrix=np.copy(matrix).astype('float64') 
    copy_matrix[row1,:] = matrix[row2,:]
    copy_matrix[row2,:] = matrix[row1,:]
    return copy_matrix

# Multiple all entries in a row by a nonzero number
def scale(matrix, row, scalar):
    copy_matrix=np.copy(matrix).astype('float64') 
    copy_matrix[row,:] = scalar*matrix[row,:]  
    return copy_matrix

# Replacing a row by the sum of itself and a multiple of another 
def replace(matrix, row1, row2, scalar):
    copy_matrix=np.copy(matrix).astype('float64')
    copy_matrix[row1] = matrix[row1]+ scalar * matrix[row2] 
    return copy_matrix
A1 = replace(A, 1, 0, -2)
A2 = replace(A1, 2, 0, -1)
A3 = replace(A2, 2, 1, 2)
A4 = scale(A3, 2, -1/5)
A5 = replace(A4, 1, 2, 1)
A6 = replace(A5, 0, 1, -1)
A7 = replace(A6, 0, 2, -1)
A7
array([[ 1.,  0.,  0., -3.],
       [ 0.,  1.,  0.,  2.],
       [-0., -0.,  1.,  3.]])

A7 is in RREF.

  1. Find the solution set of the following system of equations

\[ x - y + 3z = 0 \]
\[ 6x - y + 4z = 1 \]
\[ 3x + 2y - 4z = 2 \]

Solution:

We can change the system of equations into augmented matrix \(B\), and put it into RREF to solve.

B = np.array([[1,-1,3,0],[6,-1,4,1],[3,2,-4,2]])
B1 = replace(B, 1, 2, -2)
B2 = replace(B1, 2, 0, -3)
B3 = swap(B2, 1, 2)
B4 = replace(B3, 2, 1, 1)
B5 = replace(B4, 1, 2, 1)
B6 = scale(B5, 2, -1)
B7 = replace(B6, 1, 2, 14)
B8 = scale(B7, 1, 1/5)
B9 = replace(B8, 0, 1, 1)
B10 = replace(B9, 0, 2, -3)
B10
array([[ 1.,  0.,  0.,  0.],
       [ 0.,  1.,  0.,  3.],
       [-0., -0.,  1.,  1.]])

B10 is in reduced echelon form, and gives us the solutions \(x = 0\), \(y = 3\) and \(z = 1\).

  1. Determine if the following vectors form a linearly independent or a linearly dependent set:

    a.

\[\begin{split} \vec{v_1} = \begin{bmatrix} 1\\2\\0\\ \end{bmatrix} + \begin{bmatrix} 3\\1\\5\\ \end{bmatrix} + \begin{bmatrix} 4\\2\\3\\ \end{bmatrix} \end{split}\]
b.
\[\begin{split} \vec{v_2} = \begin{bmatrix} 1\\-4\\-2\\0\\ \end{bmatrix} + \begin{bmatrix} -3\\12\\-6\\0\\ \end{bmatrix} \end{split}\]

Solution:

a. A set of vectors form a linearly independent set if a matrix (\(C\)) made up of the vectors has only the trivial solution. Let’s find out the type of solution:

C = np.array([[1,3,4,0],[2,1,2,0],[0,5,3,0]])
C
array([[1, 3, 4, 0],
       [2, 1, 2, 0],
       [0, 5, 3, 0]])
C1 = replace(C, 1, 0, -2)
C1
array([[ 1.,  3.,  4.,  0.],
       [ 0., -5., -6.,  0.],
       [ 0.,  5.,  3.,  0.]])
C2 = replace(C1, 2, 1, 1)
C2
array([[ 1.,  3.,  4.,  0.],
       [ 0., -5., -6.,  0.],
       [ 0.,  0., -3.,  0.]])

C2 gives us \(-3 = 0\), which is impossible and means the only solution is the trivial solution. The set of vectors is linearly independent.

b. By theorem 3, a set of 2 vectors is linearly dependent if and only if one is a multiple of another. The second vector is a multiple of the first by a factor of \(-3\), meaning the set of vectors is linearly dependent.

  1. Write the general solution of the linear system corresponding to the augmented matrix \(D\).

\[\begin{split} D = \begin{bmatrix} 2 & 3 & 0 & 1\\ 2 & 4 & 2 & 2\\ 1 & 2 & 1 & 1\\ \end{bmatrix} \end{split}\]

Solution:

D = np.array([[2,3,0,1],[1,2,1,1],[2,4,2,2]])
D1 = replace(D, 0, 1, -1)
D1
array([[ 1.,  1., -1.,  0.],
       [ 1.,  2.,  1.,  1.],
       [ 2.,  4.,  2.,  2.]])
D2 = replace(D1, 2, 1, -2)
D2
array([[ 1.,  1., -1.,  0.],
       [ 1.,  2.,  1.,  1.],
       [ 0.,  0.,  0.,  0.]])
D3 = replace(D2, 1, 0, -1)
D3
array([[ 1.,  1., -1.,  0.],
       [ 0.,  1.,  2.,  1.],
       [ 0.,  0.,  0.,  0.]])
D4 = replace(D3, 0, 1, -1)
D4
array([[ 1.,  0., -3., -1.],
       [ 0.,  1.,  2.,  1.],
       [ 0.,  0.,  0.,  0.]])

Since we are left with an empty row, we see that for any \(y \in \mathbb{R}\) we have a unique solution. A general solution for this system is:

\[\begin{split} \begin{bmatrix} x\\ y\\ z\\ \end{bmatrix} = \begin{bmatrix} {\frac{1}{2}-\frac{3}{2}y}\\ {y}\\ {\frac{1}{2}-\frac{y}{2}}\\ \end{bmatrix} = \begin{bmatrix} {\frac{1}{2}}\\ 0\\ {\frac{1}{2}}\\ \end{bmatrix} + \begin{bmatrix} {-\frac{3}{2}y}\\ {y}\\ {-\frac{y}{2}}\\ \end{bmatrix} = \begin{bmatrix} {\frac{1}{2}}\\ 0\\ {\frac{1}{2}}\\ \end{bmatrix} + y\begin{bmatrix} {-\frac{3}{2}}\\ {1}\\ {-\frac{1}{2}}\\ \end{bmatrix} \end{split}\]

9.9.1. Linear Systems Solutions#

9.9.2. Matrices and Determinants Solutions#

9.9.3. Linear Transformations Solutions#

9.9.4. Eigenvalues and Eigenvectors Solutions#

9.9.5. Orthoganality Solutions#