# Section 3.1 RREF exercises


```python
from sympy import *
init_printing()

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

## RREF

### E3.1


```python
AUG = Matrix([
  [3,      3, 6],
  [2, S(3)/2, 5]])
AUG
```


```python
AUG.rref()
# solution is x=4, y=-2
```

### Verify the solution geometrically


```python
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
```


    <IPython.core.display.Javascript object>






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


### E3.2


```python
A = Matrix([
         [3,       3,  6],
         [2,  S(3)/2,  5]])
A
```


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


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


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


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

### E3.3


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


```python
# verify geomtetrically
AUGA = Matrix([
 [3, 3,  6],
 [1, 1,  5]])

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


    <IPython.core.display.Javascript object>






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



```python

```


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


```python
# 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
```


    <IPython.core.display.Javascript object>






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



```python
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}
```


```python
# 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}
```


```python
# 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
```


    <IPython.core.display.Javascript object>






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



```python

```


```python

```

## Matrix equations


```python

```


```python

```


```python

```


```python

```

## 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}\!.
$$


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

P = P1*P2
P
```


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

## Determinants


```python

```


```python

```


```python

```

## Matrix inverse


```python

```

ca367116aadf1519b9eb1af96992a9642206d9dc
ipynb
Jupyter Notebook
chapter03_exercises.ipynb
ChidinmaKO/noBSLAnotebooks
c0102473f1e6625fa5fb62768d4545059959fa26
MIT
chapter03_exercises.ipynb
ChidinmaKO/noBSLAnotebooks
c0102473f1e6625fa5fb62768d4545059959fa26
MIT
chapter03_exercises.ipynb
ChidinmaKO/noBSLAnotebooks
c0102473f1e6625fa5fb62768d4545059959fa26
MIT
Qwen/Qwen-72B
1. YES
2. YES