Section 3.1 RREF exercises


In [1]:
from sympy import *
init_printing()

%matplotlib notebook
import matplotlib.pyplot as mpl
from util.plot_helpers import plot_augmat # helper function

RREF

E3.1


In [2]:
AUG = Matrix([
  [3,      3, 6],
  [2, S(3)/2, 5]])
AUG


Out[2]:
$$\left[\begin{matrix}3 & 3 & 6\\2 & \frac{3}{2} & 5\end{matrix}\right]$$

In [3]:
AUG.rref()
# solution is x=4, y=-2


Out[3]:
$$\left ( \left[\begin{matrix}1 & 0 & 4\\0 & 1 & -2\end{matrix}\right], \quad \left ( 0, \quad 1\right )\right )$$

Verify the solution geometrically


In [4]:
AUG = Matrix([
  [3,      3,  6],
  [2, S(3)/2,  5]])

fig = mpl.figure()
plot_augmat(AUG)
# the solution (4,-2) is where the two lines intersect


Line 1:  3x +3y = 6
Line 2:  2x +1y = 5

E3.2


In [5]:
A = Matrix([
         [3,       3,  6],
         [2,  S(3)/2,  5]])
A


Out[5]:
$$\left[\begin{matrix}3 & 3 & 6\\2 & \frac{3}{2} & 5\end{matrix}\right]$$

In [6]:
# First row operation:  R1  <-- 1/3*R1
A[0,:] = A[0,:]/3
A


Out[6]:
$$\left[\begin{matrix}1 & 1 & 2\\2 & \frac{3}{2} & 5\end{matrix}\right]$$

In [7]:
# Second row operation:  R2  <-- R2 - 2*R1
A[1,:] = A[1,:] - 2*A[0,:]
A


Out[7]:
$$\left[\begin{matrix}1 & 1 & 2\\0 & - \frac{1}{2} & 1\end{matrix}\right]$$

In [8]:
# Third row operation:  R2  <-- -2*R2
A[1,:] = -2*A[1,:]
A


Out[8]:
$$\left[\begin{matrix}1 & 1 & 2\\0 & 1 & -2\end{matrix}\right]$$

In [9]:
# Fourth row operation:  R1  <-- R1 - R2
A[0,:] = A[0,:] - A[1,:]
A


Out[9]:
$$\left[\begin{matrix}1 & 0 & 4\\0 & 1 & -2\end{matrix}\right]$$

E3.3


In [10]:
AUGA = Matrix([
 [3, 3,  6],
 [1, 1,  5]])
AUGA.rref()
# no solutions since second row   0x+0y == 1  is impossible


Out[10]:
$$\left ( \left[\begin{matrix}1 & 1 & 0\\0 & 0 & 1\end{matrix}\right], \quad \left ( 0, \quad 2\right )\right )$$

In [11]:
# verify geomtetrically
AUGA = Matrix([
 [3, 3,  6],
 [1, 1,  5]])

fig = mpl.figure()
plot_augmat(AUGA)
# no solution since lines two lines are parallel


Line 1:  3x +3y = 6
Line 2:  1x +1y = 5

In [ ]:


In [12]:
AUGB = Matrix([
  [3,     3,  6],
  [2, S(3)/2, 3]])
AUGB.rref()
# one solution x=0, y=2


Out[12]:
$$\left ( \left[\begin{matrix}1 & 0 & 0\\0 & 1 & 2\end{matrix}\right], \quad \left ( 0, \quad 1\right )\right )$$

In [13]:
# verify geomtetrically
AUGB = Matrix([
  [3,     3,  6],
  [2, S(3)/2, 3]])

fig = mpl.figure()
plot_augmat(AUGB)
# the solution (0,2) is where the two lines intersect


Line 1:  3x +3y = 6
Line 2:  2x +1y = 3

In [14]:
AUGC = Matrix([
  [3, 3,  6],
  [1, 1,  2]])
AUGC.rref()
# infinitely many soln's of the form  point + s*dir, for s in \mathbb{R}


Out[14]:
$$\left ( \left[\begin{matrix}1 & 1 & 2\\0 & 0 & 0\end{matrix}\right], \quad \left ( 0\right )\right )$$

In [15]:
# to complete the solution,
# observe the second column is a free varible y = s 
# and thus we have these equations:
#   x +  s = 2
#  0x + 0s = 0   (trivial eqn.)
#        y = s   (def'n of free variable)
# thus solution is:
#      [x,y]  =  [2-s,s]  =  [2,0] + s*[-1,1]     for s in \mathbb{R}

In [16]:
# verify geomtetrically
AUGC = Matrix([
  [3, 3,  6],
  [1, 1,  2]])

fig = mpl.figure()
plot_augmat(AUGC)
# the solution is infinite since two lines are the same


Line 1:  3x +3y = 6
Line 2:  1x +1y = 2

In [ ]:


In [ ]:

Matrix equations


In [ ]:


In [ ]:


In [ ]:


In [ ]:

Matrix product

E3.5

Compute the following matrix products: $$ P = \begin{bmatrix} 1&2 \\ 3&4 \end{bmatrix} \begin{bmatrix} 5&6 \\ 7&8 \end{bmatrix} \quad \textrm{and} \quad Q = \begin{bmatrix} 3& 1 & 2& 2 \\ 0 & 2 & -2 & 1 \end{bmatrix}\!\! % \begin{bmatrix} -2 & 3 \\ \ \ 1 & 0 \\ -2 & \!\!-2 \\ \ \ 2 & 2 \end{bmatrix}\!. $$


In [2]:
# define matrices
P1 = Matrix([
    [1, 2],
    [3, 4]])
P2 = Matrix([
    [5, 6],
    [7, 8]])

P = P1*P2
P


Out[2]:
$$\left[\begin{matrix}19 & 22\\43 & 50\end{matrix}\right]$$

In [ ]:
# define matrices
Q1 = Matrix([[3, 1,  2, 2],
             [0, 2, -2, 1]])
Q2 = Matrix([[-2,  3],
             [ 1,  0],
             [-2, -2],
             [ 2,  2]])

Determinants


In [ ]:


In [ ]:


In [ ]:

Matrix inverse


In [ ]: