```python
from IPython.core.display import HTML, Image
css_file = 'style.css'
HTML(open(css_file, 'r').read())
```

<link href='http://fonts.googleapis.com/css?family=Alegreya+Sans:100,300,400,500,700,800,900,100italic,300italic,400italic,500italic,700italic,800italic,900italic' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Arvo:400,700,400italic' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=PT+Mono' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Shadows+Into+Light' rel='stylesheet' type='text/css'>
<link href='http://fonts.googleapis.com/css?family=Philosopher:400,700,400italic,700italic' rel='stylesheet' type='text/css'>

```python
from sympy import init_printing, symbols, Matrix
from warnings import filterwarnings
```

```python
init_printing(use_latex='mathjax')
filterwarnings('ignore')
```

# Exam review

### Question 1

* Consider three non-zero vectors in ℝ7
    * What is the dimension of the subspace that they can span?

#### Solution 1

* One, two, or three
* They can't span a subspace of higher dimension as there are only three vectors
* Zero cannot be an answer, because they are all non-zero vectors

### Question 2

* Part 1
    * Consider a 5×3 matrix in echelon form with three pivots
        * What's the nullspace
*  Part 2
    * Consider a 10×3 matrix of form the form below and calculate its rank and echelon form
$$ \begin{bmatrix} R \\ 2R \end{bmatrix} $$
* Part 3
    * Give the row-reduced form of the matrix
$$ \begin{bmatrix} U & U \\ U & 0 \end{bmatrix} $$

#### Solution 2

* Part 1
    * The nullspace can only be the zero vector
$$ \begin{bmatrix} 0 \\ 0 \\ 0 \end{bmatrix} $$
    * With three columns all with pivots, we have *n* - *r* = 3 - 3 = 0

* Part 2
    * Row reduction will take us to
$$ \begin{bmatrix} R \\ 0 \end{bmatrix} $$

* Part 3
$$ \begin{bmatrix} U & U \\ 0 & -U \end{bmatrix} $$
    * In reduced row echelon form
$$ \begin{bmatrix} U & 0 \\ 0 & U \end{bmatrix} $$

### Question 3

* Consider
$$ {A} \overline {x} = \begin{bmatrix} 2 \\ 4 \\ 2 \end{bmatrix} $$
* With
$$ {x} = \begin{bmatrix} 2 \\ 0 \\ 0 \end{bmatrix} + {c}\begin{bmatrix} 1 \\ 1 \\ 0 \end{bmatrix} + {d}\begin{bmatrix} 0 \\ 0 \\ 1 \end{bmatrix} $$
* Part 1
    * What is the dimension of the rowspace of A and the nullspace of A
* Part 2
    * For what values of **b** can A**x** = **b** be solved?

#### Solution 3

* Part 1
    * Well, the size of the matrix must be 3×3
    * The dimension of the nullspace is 2 (because two non-pivot columns)
    * With *n* - *r* = 2, we have *r* = 1, which must hold for the rowspace of A
* Part 2
    * Looking only at the particular solution we must have
$$ 2\begin{bmatrix} { a }_{ 11 } \\ { a }_{ 21 } \\ { a }_{ 31 } \end{bmatrix}=\begin{bmatrix} 2 \\ 4 \\ 2 \end{bmatrix}\\ \therefore \quad \begin{bmatrix} { a }_{ 11 } \\ { a }_{ 21 } \\ { a }_{ 31 } \end{bmatrix}\quad =\quad \begin{bmatrix} 1 \\ 2 \\ 1 \end{bmatrix}\\ \therefore \quad \begin{bmatrix} { a }_{ 11 } & { a }_{ 12 } & { a }_{ 13 } \\ { a }_{ 21 } & { a }_{ 22 } & { a }_{ 23 } \\ { a }_{ 31 } & { a }_{ 32 } & { a }_{ 33 } \end{bmatrix}=\begin{bmatrix} 1 & -1 & 0 \\ 2 & -2 & 0 \\ 1 & -1 & 0 \end{bmatrix} $$
* So, how did I get the last two columns?
    * Well, they cannot be independent of the first column and the last column must have all zeros to set up the first variable solution fr *x*3, i.e. *x*3 = *d*
    * Adding column 2 to column 1 to get all zeros must result in what you seen for column 2

```python
A = Matrix([[1, -1, 0], [2, -2, 0], [1, -1, 0]])
x_vect = Matrix([2, 0, 0])
x_vect_null_1 = Matrix([1, 1, 0])
x_vect_null_2 = Matrix([0, 0, 1])
A * x_vect + A * x_vect_null_1 + A * x_vect_null_2
```

$$\left[\begin{matrix}2\\4\\2\end{matrix}\right]$$

```python
A.nullspace()
```

$$\begin{bmatrix}\left[\begin{matrix}1\\1\\0\end{matrix}\right], & \left[\begin{matrix}0\\0\\1\end{matrix}\right]\end{bmatrix}$$

* It can only be solve for scalar multiples of
$$ \begin{bmatrix} 1 \\ 2 \\ 1 \end{bmatrix} $$

### Question and solution 4

* If the nullspace of a square matrix is the zero vector only, does the nullspace of the transpose also only contain the zero vector
    * Yes

* Consider the matrix space of all 5×5 matrices; do the invertible 5×5 matrices form a subspace
    * No, as the set of invertible matrices would not contain the zero matrix
    * Also if I add two invertible matrices, I don't know if the resultant matrix is invertible
    * The singular ones won't work either as adding two we also don't know if the resultant matrix is invertible

* If B2 = **0**, is B = **0**?
    * No, i.e
$$ {B} = \begin{bmatrix} 0 & 1 \\ 0 & 0 \end{bmatrix} $$

```python
B = Matrix([[0, 1], [0, 0]])
B ** 2 # Could also use B * B
```

$$\left[\begin{matrix}0 & 0\\0 & 0\end{matrix}\right]$$

```python
B == B * B # Checking by Boolean statement
```

    False

* A system of *n* unknowns in *n* equations is solvable for every **b** if the columns of the matrix of coefficients are independent?
    * Yes

### Question 5

$$ B=\begin{bmatrix} 1 & 1 & 0 \\ 0 & 1 & 0 \\ 1 & 0 & 1 \end{bmatrix}\begin{bmatrix} 1 & 0 & -1 & 2 \\ 0 & 1 & 1 & -1 \\ 0 & 0 & 0 & 0 \end{bmatrix} $$
* Calculate the basis of the nullspace of B

#### Solution 5

* B will have to be a 3×4 matrix
* The last row will be all zeros

```python
B1 = Matrix([[1, 1, 0], [0, 1, 0], [1, 0, 1]])
B2 = Matrix([[1, 0, -1, 2], [0, 1, 1, -1], [0, 0, 0, 0]])
B1, B2
```

$$\begin{pmatrix}\left[\begin{matrix}1 & 1 & 0\\0 & 1 & 0\\1 & 0 & 1\end{matrix}\right], & \left[\begin{matrix}1 & 0 & -1 & 2\\0 & 1 & 1 & -1\\0 & 0 & 0 & 0\end{matrix}\right]\end{pmatrix}$$

* It is important to note that of we multiply an invertible matrix by another matrix (assuming multiplication is possible by the shape of the matrices), then the invertible one (B1 above), plays no part in the nullspace
    * N(CD) = N(D) if C is invertible
* We therefor only have to look at B2
* It has 2 pivot columns, i.e. rank is *r* = 2
* It will therefor have 2 independent variables, making the nullspace 2-dimensional

```python
B = B1 * B2
B.nullspace()
```

$$\begin{bmatrix}\left[\begin{matrix}1\\-1\\1\\0\end{matrix}\right], & \left[\begin{matrix}-2\\1\\0\\1\end{matrix}\right]\end{bmatrix}$$

```python

```

Mathematics/Linear Algebra/0.0 MIT-18.06 - Jupyter/Lecture_13_Quiz1_review.ipynb