In [1]:
from sympy import *
init_printing()
%matplotlib notebook
import matplotlib.pyplot as mpl
from util.plot_helpers import plot_augmat # helper function
In [2]:
AUG = Matrix([
[3, 3, 6],
[2, S(3)/2, 5]])
AUG
Out[2]:
In [3]:
AUG.rref()
# solution is x=4, y=-2
Out[3]:
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
In [5]:
A = Matrix([
[3, 3, 6],
[2, S(3)/2, 5]])
A
Out[5]:
In [6]:
# First row operation: R1 <-- 1/3*R1
A[0,:] = A[0,:]/3
A
Out[6]:
In [7]:
# Second row operation: R2 <-- R2 - 2*R1
A[1,:] = A[1,:] - 2*A[0,:]
A
Out[7]:
In [8]:
# Third row operation: R2 <-- -2*R2
A[1,:] = -2*A[1,:]
A
Out[8]:
In [9]:
# Fourth row operation: R1 <-- R1 - R2
A[0,:] = A[0,:] - A[1,:]
A
Out[9]:
In [10]:
AUGA = Matrix([
[3, 3, 6],
[1, 1, 5]])
AUGA.rref()
# no solutions since second row 0x+0y == 1 is impossible
Out[10]:
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
In [ ]:
In [12]:
AUGB = Matrix([
[3, 3, 6],
[2, S(3)/2, 3]])
AUGB.rref()
# one solution x=0, y=2
Out[12]:
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
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]:
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
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
In [ ]:
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]:
In [ ]:
# define matrices
Q1 = Matrix([[3, 1, 2, 2],
[0, 2, -2, 1]])
Q2 = Matrix([[-2, 3],
[ 1, 0],
[-2, -2],
[ 2, 2]])
In [ ]:
In [ ]:
In [ ]:
In [ ]: