diff --git a/challenge_5a.ipynb b/challenge_5a.ipynb
new file mode 100644
index 0000000..44e0bbe
--- /dev/null
+++ b/challenge_5a.ipynb
@@ -0,0 +1,1218 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "view-in-github",
+ "colab_type": "text"
+ },
+ "source": [
+ ""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "n4zfZ9NlIGm4"
+ },
+ "source": [
+ "![header.png](https://lh4.googleusercontent.com/FWBHWkTBQHZQrtGwvdPeHwpTNJ2PQiQYa7zfSxQwhHH92n34SU9dkcbvp0BbBmtK1djie1C1_f8Y9t8XbDHYXxlO5PKQZO2JdB_Xfe_4wD9GIEcUW6KSoE8YzVioVVOPQQ=w5014)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "rGnFQwR3IGm7"
+ },
+ "source": [
+ "Before you turn this problem in, make sure everything runs as expected. First, **restart the kernel** (in the menubar, select Kernel$\\rightarrow$Restart) and then **run all cells** (in the menubar, select Cell$\\rightarrow$Run All).\n",
+ "\n",
+ "Make sure you fill in any place that says `YOUR CODE HERE` or \"YOUR ANSWER HERE\", as well as your name and collaborators below:"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 1,
+ "metadata": {
+ "id": "EajMypcKIGm7"
+ },
+ "outputs": [],
+ "source": [
+ "NAME = \"Zmavli Caimle\"\n",
+ "COLLABORATORS = \"JD\""
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "x0V3fmOpIGm9"
+ },
+ "source": [
+ "---"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "9aSJ0wvRIGm-"
+ },
+ "source": [
+ "# Challenge 5A: Solving $A\\vec{x} = \\vec{b}$\n",
+ "\n",
+ "> _It is impossible to dissociate language from science or science from language, because every natural science always involves three things: the sequence of phenomena on which the science is based; the abstract concepts which call these phenomena to mind; and the words in which the concepts are expressed. To call forth a concept, a word is needed; to portray a phenomenon, a concept is needed. All three mirror one and the same reality._\n",
+ ">\n",
+ "> — Antoine Lavoisier (1789)\n",
+ "\n",
+ "In this challenge and its other part, you will learn what matrices really _are_ in the course of trying to understand two primary objects of study in linear algebra, namely the following matrix equations:\n",
+ "\n",
+ "1. $A\\vec{x} = \\vec{b}$, used to solve systems of equations\n",
+ "2. $A\\vec{x} = \\lambda \\vec{x}$, used to understand how matrices _transform_ spaces\n",
+ "\n",
+ "(Here, $\\vec{b}$ is some arbitrary vector and $\\lambda$ is a scalar.)\n",
+ "\n",
+ "By the end of this challenge, you should:\n",
+ "\n",
+ "- [x] possess the language to talk about _linear transformations_, and how they enable you to morph and mold (vector) spaces as you see fit\n",
+ "- [x] be able to solve systems of equations, and furthermore know exactly when you can and cannot do so\n",
+ "\n",
+ "Let's jump right into it."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "FQMl-VRyIGnK"
+ },
+ "source": [
+ "## Problem 1: Write each of the following systems of equations as a single matrix:\n",
+ "\n",
+ "a.\n",
+ "$\n",
+ "\\begin{cases}\n",
+ "3y - z &= 0 \\\\\n",
+ "-2x + y + 2z &= 0 \\\\\n",
+ "x - 5z &= 0\n",
+ "\\end{cases}\n",
+ "$\n",
+ "\n",
+ "b.\n",
+ "$\n",
+ "\\begin{cases}\n",
+ "2x_1 + 3x_2 - x_3 &= 1 \\\\\n",
+ "-2x_2 + x_3 &= 2 \\\\\n",
+ "x_1 - 2x_3 &= -1\n",
+ "\\end{cases}\n",
+ "$"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "a: $\\begin{bmatrix}\n",
+ "0 & 3 & 1 \\\\\n",
+ "-2 & 1 & 2 \\\\\n",
+ "1 & 0 & -5\n",
+ "\\end{bmatrix}$\n",
+ "\n",
+ "b: $\\begin{bmatrix}\n",
+ "2 & 3 & -1 & -1\\\\\n",
+ "0 & -2 & 1 & -2\\\\\n",
+ "1 & 0 & -2 & 1\n",
+ "\\end{bmatrix}$\n"
+ ],
+ "metadata": {
+ "id": "CuJh_5y2UDFu"
+ }
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "U0ESFZDxIGnL"
+ },
+ "source": [
+ "## Definition: (linear transformation)\n",
+ "\n",
+ "A **linear transformation** $T: \\mathbb{R}^n \\to \\mathbb{R}^m$ is a mapping such that, for scalars $a$ and all $\\vec{v}$, $\\vec{w}$ $\\in$ $\\mathbb{R}^n$:\n",
+ "\n",
+ "$$\n",
+ "T(\\vec{v} + \\vec{w}) = T(\\vec{v}) + T(\\vec{w})\n",
+ "$$\n",
+ "\n",
+ "and\n",
+ "\n",
+ "$$\n",
+ "T(a\\vec{v}) = aT(\\vec{v})\n",
+ "$$"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "lF_T-XfVIGnN"
+ },
+ "source": [
+ "**Q**: What happens to the zero vector $\\vec{0}$ when you apply a linear transformation to it?\n",
+ "\n",
+ "\n",
+ "Answer
\n",
+ "Choose $a = 0$ so that $T(0 \\vec{v}) = T(\\vec{0}) = (0)T(\\vec{v}) = \\vec{0}$. In other words, linear transformations always map the zero vector to itself.\n",
+ "\n",
+ "Alternatively, all linear transformations preserve the _origin_.\n",
+ " "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "eC5_sS7XIGnO"
+ },
+ "source": [
+ "## Proposition I: Matrices are linear transformations\n",
+ "\n",
+ "1. Any $m \\times n$ matrix defines a linear transformation $T: \\mathbb{R}^n \\to \\mathbb{R}^m$ by matrix multiplication:\n",
+ "\n",
+ "$$\n",
+ "T(\\vec{v}) = A\\vec{v}\n",
+ "$$\n",
+ "\n",
+ "2. Every linear transformation $T: \\mathbb{R}^n \\to \\mathbb{R}^m$ is given by the $m \\times n$ matrix $[T]$:\n",
+ "\n",
+ "$$\n",
+ "T(\\vec{v}) = [T]\\vec{v}\n",
+ "$$\n",
+ "\n",
+ "where the ith column of $[T]$ is $T(\\vec{e_i})$"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "Ofo_UWBlIGnP"
+ },
+ "source": [
+ "## Problem 2: Prove Proposition I."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "A linear transformation can be defined by a matrix that describes the position of the unit vector(s) after the linear transformation is performed. The number of rows $n$ represent the number of dimensions, and the number of columns $m$ represent the number of unit vectors. The entries describe new coordinates of the unit vectors after the transformation is performed."
+ ],
+ "metadata": {
+ "id": "UcxqLLnAM3rx"
+ }
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "_zYPB8JIIGnQ"
+ },
+ "source": [
+ "## Example: Identity transformation\n",
+ "\n",
+ "The identity transformation $\\text{id}: \\mathbb{R}^n \\to \\mathbb{R}^n$ is linear and is given by the $n \\times n$ identity matrix.\n",
+ "\n",
+ "Applying it to any vector leaves it unchanged."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "oowe94p_IGnS"
+ },
+ "source": [
+ "## Example: Scaling transformation\n",
+ "\n",
+ "The transformation $T$ having the form $\\begin{bmatrix} a & 0 \\\\ 0 & a \\end{bmatrix}$ scales any vector in $\\mathbb{R}^2$ by $a$, since $T\\vec{e_1} = \\begin{bmatrix} a \\\\ 0 \\end{bmatrix}$ and $T\\vec{e_2} = \\begin{bmatrix} 0 \\\\ a \\end{bmatrix}$"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "e-G3A7j4IGnS"
+ },
+ "source": [
+ "## Example: Rotation transformation\n",
+ "\n",
+ "The transformation $R$ that rotates a vector by $\\theta$ counterclockwise around the origin is linear, and is given by:\n",
+ "\n",
+ "$$\n",
+ "[R] = [R(\\vec{e_1}), R(\\vec{e_2})] = \\begin{bmatrix} \\cos{\\theta} & -\\sin{\\theta} \\\\ \\sin{\\theta} & \\cos{\\theta} \\end{bmatrix}\n",
+ "$$\n",
+ "\n",
+ "where we denote the individual columns of $[R]$ by $R(\\vec{e_1})$ and $R(\\vec{e_2})$."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "jp-MarkdownHeadingCollapsed": true,
+ "id": "NNGRRBwRIGnT"
+ },
+ "source": [
+ "## Proposition II: Composition corresponds to matrix multiplication\n",
+ "\n",
+ "If $S: \\mathbb{R}^n \\to \\mathbb{R}^m$ and $T: \\mathbb{R}^m \\to \\mathbb{R}^l$ are linear transformations represented by matrices $[S]$ and $[T]$ respectively, then the function composition $T \\circ S$ is linear and $$[T \\circ S] = [T][S]$$\n",
+ "\n",
+ "---\n",
+ "\n",
+ "Does this make sense? For example, if you want to apply the scaling and rotation transformations to a vector, you can just multiply said vector their representative matrices. The magic is that this works for _any_ linear transformation that can be represented by a matrix."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "3SKQRzqMIGnT"
+ },
+ "source": [
+ "## Definition: (affine transformation)\n",
+ "\n",
+ "A map $\\vec{f}: \\mathbb{R}^n \\to \\mathbb{R}^m$ is **affine** if the function $\\vec{x} \\mapsto \\vec{f(\\vec{x})} - \\vec{f(\\vec{0})}$ is linear.\n",
+ "\n",
+ "---\n",
+ "\n",
+ "In other words, an affine transformation is what you get if you do a linear transformation _and then_ move the $\\vec{0}$ somewhere else. The reason why we're even bothering with this is because the layers of a neural network are generally _not_ linear but a combination of an affine transformation and a nonlinear activation function that determines what the neuron should output given the magnitude of its inputs. You have already seen one such activation function in Challenge 04: the sigmoid, and we will see more later.\n",
+ "\n",
+ "For now, we study linear transformations because they are, in some sense, stuff we can completely understand. And because of this, all the theory of more complicated transformations are usually formulated on top of them."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "7GwuBQDUIGnT"
+ },
+ "source": [
+ "**Q**: Is the map $\\begin{pmatrix} x \\\\ y \\end{pmatrix} \\mapsto \\begin{pmatrix} x - y + 2 \\\\ 2x + y + 1 \\end{pmatrix}$ linear or affine?\n",
+ "\n",
+ "\n",
+ "Answer
\n",
+ "It's affine, since it maps the zero vector $\\begin{pmatrix} 0 \\\\ 0 \\end{pmatrix} \\mapsto \\begin{pmatrix} 2 \\\\ 1 \\end{pmatrix}$ and not to itself.\n",
+ " "
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "SBve5US2IGnT"
+ },
+ "source": [
+ "## Definition: (dot product)\n",
+ "\n",
+ "The **dot product** of two vectors $\\vec{x}, \\vec{y} \\in \\mathbb{R}^n$ is given by:\n",
+ "\n",
+ "$$\n",
+ "\\vec{x} \\cdot \\vec{y} = \\begin{bmatrix} x_1 \\\\ \\vdots \\\\ x_n \\end{bmatrix} \\cdot \\begin{bmatrix} y_1 \\\\ \\vdots \\\\ y_n \\end{bmatrix} = \\sum{x_i y_i}\n",
+ "$$\n",
+ "\n",
+ "---\n",
+ "\n",
+ "Note that we can also write this as $\\vec{x} \\cdot \\vec{y} = \\vec{x}^T \\, \\vec{y} = \\vec{y}^T \\, \\vec{x}$.\n",
+ "\n",
+ "Also, the dot product produces a _scalar_.\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "cxD_9R8MIGnU"
+ },
+ "source": [
+ "## Definition: (length of a vector)\n",
+ "\n",
+ "The **length of a vector** $\\vec{v}$ is\n",
+ "\n",
+ "$$\n",
+ "|\\vec{v}| = \\sqrt{\\vec{v} \\cdot \\vec{v}} = \\sqrt{\\sum{v_i^2}}\n",
+ "$$\n",
+ "\n",
+ "A vector of length 1 is also called a **unit vector**, and you can always turn $\\vec{v}$ into a unit vector in the same direction by dividing it by its length:\n",
+ "\n",
+ "$$\n",
+ "\\hat{v} = \\frac{\\vec{v}}{|\\vec{v}|}\n",
+ "$$"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "kbgzmfcSIGnU"
+ },
+ "source": [
+ "## Definition: (angle between two vectors)\n",
+ "\n",
+ "The angle $\\alpha$ between two vectors $\\vec{v}$ and $\\vec{w}$ is given by:\n",
+ "\n",
+ "$$\n",
+ "\\vec{v} \\cdot \\vec{w} = |\\vec{v}||\\vec{w}| \\cos{\\alpha}\n",
+ "$$\n",
+ "\n",
+ "---\n",
+ "\n",
+ "When $\\alpha = \\pi / 2 = 90{^\\circ}$, $\\vec{v} \\cdot \\vec{w} = 0$. In this case, we say that the vectors are **orthogonal** to each other."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "fM0Y0jTSIGnU"
+ },
+ "source": [
+ "## Problem (bonus): Prove the following trigonometric identities using the rotation transformation.\n",
+ "\n",
+ "a. $\\cos{\\alpha + \\beta} = \\cos{\\alpha}\\cos{\\beta} - \\sin{\\alpha}\\sin{\\beta}$\n",
+ "\n",
+ "b. $\\sin{\\alpha + \\beta} = \\sin{\\alpha}\\cos{\\beta} + \\cos{\\alpha}\\sin{\\beta}$"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "XQUJQFd1IGnV"
+ },
+ "source": [
+ "## Definition: (length of a matrix)\n",
+ "\n",
+ "The **length of a matrix** $A$ is simply the square root of the sum of each of its entries squared, or:\n",
+ "\n",
+ "$$\n",
+ "|A|^2 = \\sum{a}^2_{ij}\n",
+ "$$\n",
+ "\n",
+ "---\n",
+ "\n",
+ "We call this a _length_ because it allows us to talk about how 'close' linear transformations are to each other. Unfurl an $m \\times n$ matrix as a point in $\\mathbb{R}^{mn}$ (i.e. a point with $mn$ entries), and by comparing its length with other matrices of the same shape we are able to precisely tell if its corresponding transformation does nearly the same thing as another.\n",
+ "\n",
+ "(Don't think too hard about this point if it didn't make sense to you. It's just a neat addition to one's mathematical intuition.)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "YJ5CYz3nIGnV"
+ },
+ "source": [
+ "## Example: Length of a matrix\n",
+ "\n",
+ "If $A = \\begin{bmatrix} 1 & 2 \\\\ 0 & 1 \\end{bmatrix}$, then $|A| = \\sqrt{1^2 + 2^2 + 0^2 + 1^2} = \\sqrt{6}$"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "tQB7qEvXIGnV"
+ },
+ "source": [
+ "---"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "Y3Ivzq5kIGnW"
+ },
+ "source": [
+ "## Example: Representing systems of equations as matrices\n",
+ "\n",
+ "Consider the following system of equations:\n",
+ "\n",
+ "\n",
+ "$$\n",
+ "\\begin{cases}\n",
+ "2x + y + 3z &= 1 \\\\\n",
+ "x - y \\, &= 1 \\\\\n",
+ "2x \\, + z &= 1\n",
+ "\\end{cases}\n",
+ "$$\n",
+ "\n",
+ "We can write this as a matrix equation if we define the **coefficient matrix**\n",
+ "\n",
+ "$$\n",
+ "A = \\begin{bmatrix} 2 & 1 & 3 \\\\ 1 & -1 & 0 \\\\ 2 & 0 & 1 \\end{bmatrix}\n",
+ "$$\n",
+ "\n",
+ "the vector of unknowns $\\vec{x} = \\begin{bmatrix} x \\\\ y \\\\ z \\end{bmatrix}$ and the constants $\\vec{b} = \\begin{bmatrix} 1 \\\\ 1 \\\\ 1 \\end{bmatrix}$, so that we can write:\n",
+ "\n",
+ "$$\n",
+ "\\begin{bmatrix} 2 & 1 & 3 \\\\ 1 & -1 & 0 \\\\ 2 & 0 & 1 \\end{bmatrix}\n",
+ "\\begin{bmatrix} x \\\\ y \\\\ z \\end{bmatrix}\n",
+ "=\n",
+ "\\begin{bmatrix} 1 \\\\ 1 \\\\ 1 \\end{bmatrix}\n",
+ "$$\n",
+ "\n",
+ "or\n",
+ "\n",
+ "$$A \\vec{x} = \\vec{b}$$\n",
+ "\n",
+ "We can even write this more compactly as the **augmented matrix** $[A | \\vec{b}]$:\n",
+ "\n",
+ "$$\n",
+ "\\begin{bmatrix}\n",
+ "2 & 1 & 3 & \\bigm| & 1 \\\\\n",
+ "1 & -1 & 0 & \\bigm| & 1 \\\\\n",
+ "2 & 0 & 1 & \\bigm| & 1\n",
+ "\\end{bmatrix}\n",
+ "$$"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "Wxq0vlZdIGnW"
+ },
+ "source": [
+ "## Definition: (row operations)\n",
+ "\n",
+ "A **row operation** on a matrix is one of the following:\n",
+ "\n",
+ "1. Multiplying a row by a nonzero number\n",
+ "2. Adding a multiple of a row to another row\n",
+ "3. Exchanging two rows"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "RraNeYejIGnX"
+ },
+ "source": [
+ "## Example: solving a matrix using row operations\n",
+ "\n",
+ "We can solve the system of equations associated with the augmented matrix $A = \\begin{bmatrix} 2 & 1 & 3 & \\bigm| & 1 \\\\ 1 & -1 & 0 & \\bigm| & 1 \\\\ 2 & 0 & 1 & \\bigm| & 1\\end{bmatrix}$ as follows:\n",
+ "\n",
+ "1. Divide row 1 by 2, add -1/2 row 1 to row 2, then subtract row 1 from row 3:\n",
+ "$$\n",
+ "\\begin{bmatrix}\n",
+ "1 & 1/2 & 3/2 & \\bigm| & 1/2 \\\\\n",
+ "0 & -3/2 & -3/2 & \\bigm| & 1/2 \\\\\n",
+ "0 & -1 & -2 & \\bigm| & 0\n",
+ "\\end{bmatrix}\n",
+ "$$\n",
+ "\n",
+ "3. Multiply row 2 by -2/3, then add result to row 3:\n",
+ "$$\n",
+ "\\begin{bmatrix}\n",
+ "1 & 1/2 & 3/2 & \\bigm| & 1/2 \\\\\n",
+ "0 & 1 & 1 & \\bigm| & -1/3 \\\\\n",
+ "0 & 0 & -1 & \\bigm| & -1/3\n",
+ "\\end{bmatrix}\n",
+ "$$\n",
+ "\n",
+ "5. Subtract 1/2 row 2 from row 1:\n",
+ "$$\n",
+ "\\begin{bmatrix}\n",
+ "1 & 0 & 1 & \\bigm| & 2/3 \\\\\n",
+ "0 & 1 & 1 & \\bigm| & -1/3 \\\\\n",
+ "0 & 0 & 1 & \\bigm| & 1/3\n",
+ "\\end{bmatrix}\n",
+ "$$\n",
+ "\n",
+ "7. Subtract row 3 from row 1:\n",
+ "$$\n",
+ "\\begin{bmatrix}\n",
+ "1 & 0 & 0 & \\bigm| & 1/3 \\\\\n",
+ "0 & 1 & 1 & \\bigm| & -1/3 \\\\\n",
+ "0 & 0 & 1 & \\bigm| & 1/3\n",
+ "\\end{bmatrix}\n",
+ "$$\n",
+ "\n",
+ "9. Subtract row 3 from row 2:\n",
+ "$$\n",
+ "\\begin{bmatrix}\n",
+ "1 & 0 & 0 & \\bigm| & 1/3 \\\\\n",
+ "0 & 1 & 0 & \\bigm| & -2/3 \\\\\n",
+ "0 & 0 & 1 & \\bigm| & 1/3\n",
+ "\\end{bmatrix}\n",
+ "$$\n",
+ "\n",
+ "from which we can immediately read off the solutions:\n",
+ "\n",
+ "\n",
+ "$$\n",
+ "\\begin{bmatrix}\n",
+ "x & 0 & 0 & \\bigm| & 1/3 \\\\\n",
+ "0 & y & 0 & \\bigm| & -2/3 \\\\\n",
+ "0 & 0 & z & \\bigm| & 1/3\n",
+ "\\end{bmatrix}\n",
+ "$$\n",
+ "\n",
+ "or $x = 1/3$, $y = -2/3$, and $z = 1/3$"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "8zJNj2oaIGnX"
+ },
+ "source": [
+ "## Definition: (row echelon form)\n",
+ "\n",
+ "A matrix is in **row echelon form** or **row-reduced form** if all of the following conditions are satisfied:\n",
+ "\n",
+ "1. In every row, the first nonzero entry is 1, called the **pivotal 1**.\n",
+ "2. The pivotal 1 of a lower row is always to the right of the pivotal 1 of a higher row.\n",
+ "3. In every column that contains a pivotal 1, all other entries are 0.\n",
+ "4. Any rows consisting entirely of 0's are at the bottom.\n",
+ "\n",
+ "We also say that a matrix is in **column echelon form** if its transpose is in row echelon form.\n",
+ "\n",
+ "For an augmented matrix $[A|\\vec{b}]$, we can also denote its row echelon form by $[\\tilde{A}|\\tilde{b}]$ and call $\\tilde{A}$ a **row-reduced matrix** and $\\tilde{b}$ a **row-reduced vector**.\n",
+ "\n",
+ "---\n",
+ "\n",
+ "It is possible to show that the row echelon form of a matrix is _unique_ regardless of which row operations you used to derive it."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "u2skUmJeIGnX"
+ },
+ "source": [
+ "## Example: Matrices in echelon form\n",
+ "\n",
+ "All of these matrices are in echelon form, with the pivotal 1's underlined:\n",
+ "\n",
+ "$$\n",
+ "\\begin{bmatrix}\n",
+ "\\underline{1} & 0 & 0 & 3 \\\\\n",
+ "0 & \\underline{1} & 0 & -2 \\\\\n",
+ "0 & 0 & \\underline{1} & 1\n",
+ "\\end{bmatrix}\n",
+ "$$\n",
+ "\n",
+ "$$\n",
+ "\\begin{bmatrix}\n",
+ "\\underline{1} & 1 & 0 & 0 \\\\\n",
+ "0 & 0 & \\underline{1} & 0 \\\\\n",
+ "0 & 0 & 0 & \\underline{1}\n",
+ "\\end{bmatrix}\n",
+ "$$\n",
+ "\n",
+ "$$\n",
+ "\\begin{bmatrix}\n",
+ "0 & \\underline{1} & 3 & 0 & 0 & 3 & 0 & -4 \\\\\n",
+ "0 & 0 & 0 & \\underline{1} & -2 & 1 & 0 & 1 \\\\\n",
+ "0 & 0 & 0 & 0 & 0 & 0 & \\underline{1} & 2\n",
+ "\\end{bmatrix}\n",
+ "$$"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "F9v9kZ2QIGnY"
+ },
+ "source": [
+ "**Q**: Which of these are in echelon form?\n",
+ "\n",
+ "a. $\n",
+ "\\begin{bmatrix}\n",
+ "1 & 0 & 0 & 2 \\\\\n",
+ "0 & 0 & 1 & -1 \\\\\n",
+ "0 & 1 & 0 & 1\n",
+ "\\end{bmatrix}\n",
+ "$\n",
+ "\n",
+ "b. $\n",
+ "\\begin{bmatrix}\n",
+ "1 & 1 & 0 & 1 \\\\\n",
+ "0 & 0 & 2 & 0 \\\\\n",
+ "0 & 0 & 0 & 1\n",
+ "\\end{bmatrix}\n",
+ "$\n",
+ "\n",
+ "**c. $\n",
+ "\\begin{bmatrix}\n",
+ "0 & 0 & 0 \\\\\n",
+ "1 & 0 & 0 \\\\\n",
+ "0 & 1 & 0\n",
+ "\\end{bmatrix}\n",
+ "$ This matrix is in column echelon form.**\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "IxRRFy1aIGnY"
+ },
+ "source": [
+ "## Definition: (elementary matrices)\n",
+ "\n",
+ "1. The **type 1 elementary matrix** $E_1(i, x)$ is the square matrix whose nondiagonal terms are 0, and every entry on the diagonal except for the $(i, i)$th entry which is nonzero\n",
+ "2. The **type 2 elementary matrix** $E_2(i, j, x)$, i $\\neq j$, is the square matrix whose diagonal entries are 1 and all entries 0 except for the $(i, j)$th which is x.\n",
+ "3. The **type 3 elementary matrix** $E_3(i, j), $$i \\neq j$, is the square matrix whose entries $i, j$ and $j, i$ are 1, and all other entries on the diagonal except $i,i$ and $j,j$, which are 0.\n",
+ "\n",
+ "---\n",
+ "\n",
+ "You should verify for yourself that multiplying a matrix $A$ on the left by:\n",
+ "\n",
+ "1. $E_1(i, x)$ multiplies the ith row of $A$ by $x$.\n",
+ "2. $E_2(i, j, x)$ adds ($x$ times the jth row) to the ith row.\n",
+ "3. $E_3(i, j)$ exchanges the ith and jth rows of $A$\n",
+ "\n",
+ "Or in other words, the elementary matrices are how you actually do row operations purely in the language of linear algebra."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "25sjak6hIGnZ"
+ },
+ "source": [
+ "## Examples: Elementary matrices\n",
+ "\n",
+ "1. $E_1(3, 2) = \\begin{bmatrix} 1 & 0 & 0 & 0 \\\\ 0 & 1 & 0 & 0 \\\\ 0 & 0 & 2 & 0 \\\\ 0 & 0 & 0 & 1 \\end{bmatrix}$\n",
+ " \n",
+ "2. $E_2(1, 3, -3) = \\begin{bmatrix} 1 & 0 & -3 \\\\ 0 & 1 & 0 \\\\ 0 & 0 & 1 \\end{bmatrix}$\n",
+ "\n",
+ "3. $E_3(2, 3) = \\begin{bmatrix} 1 & 0 & 0 & 0 & 0 \\\\ 0 & 0 & 1 & 0 & 0 \\\\ 0 & 1 & 0 & 0 & 0 \\\\ 0 & 0 & 0 & 1 & 0 \\\\ 0 & 0 & 0 & 0 & 1 \\end{bmatrix}$"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "DQ0pEQtFIGnZ"
+ },
+ "source": [
+ "**Q**: Let $$A = \\begin{bmatrix} 1 & 0 \\\\ 0 & 2 \\\\ 2 & 1 \\\\ 1 & 1 \\end{bmatrix}$$\n",
+ "\n",
+ "What is $E_1(3,2)A$?"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "$\n",
+ "E_1(3,2)A =\n",
+ "\\begin{bmatrix}\n",
+ "1 & 0 \\\\\n",
+ "0 & 2 \\\\\n",
+ "4 & 2 \\\\\n",
+ "1 & 1\n",
+ "\\end{bmatrix}\n",
+ "$"
+ ],
+ "metadata": {
+ "id": "GpIw-v6_VWzf"
+ }
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "VNpITGKoIGnZ"
+ },
+ "source": [
+ "## Problem 3: Using elementary matrices, row reduce each matrix in Problem 1.\n",
+ "\n",
+ "You may use `numpy` for this, but you need to show each operation."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "source": [],
+ "metadata": {
+ "id": "wHxqOTojiItw"
+ }
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "a: $\\begin{bmatrix}\n",
+ "0 & 3 & 1 \\\\\n",
+ "-2 & 1 & 2 \\\\\n",
+ "1 & 0 & -5\n",
+ "\\end{bmatrix}$\n",
+ "\n",
+ "b: $\\begin{bmatrix}\n",
+ "2 & 3 & -1 & -1\\\\\n",
+ "0 & -2 & 1 & -2\\\\\n",
+ "1 & 0 & -2 & 1\n",
+ "\\end{bmatrix}$"
+ ],
+ "metadata": {
+ "id": "RFGiAAd1iJrC"
+ }
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 2,
+ "metadata": {
+ "nbgrader": {
+ "grade": true,
+ "grade_id": "cell-175b2f95c91de232",
+ "locked": false,
+ "points": 0,
+ "schema_version": 3,
+ "solution": true,
+ "task": false
+ },
+ "id": "7eKiyl3EIGna",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "eab4d91a-967d-4749-c041-f14cfc0ae858"
+ },
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "[[1. 0. 0. 0.]\n",
+ " [0. 1. 0. 0.]\n",
+ " [0. 0. 2. 0.]\n",
+ " [0. 0. 0. 1.]]\n",
+ "[[ 1. 0. -3.]\n",
+ " [ 0. 1. 0.]\n",
+ " [ 0. 0. 1.]]\n",
+ "[[1. 0. 0. 0. 0.]\n",
+ " [0. 0. 0. 0. 0.]\n",
+ " [0. 1. 0. 0. 0.]\n",
+ " [0. 0. 0. 1. 0.]\n",
+ " [0. 0. 0. 0. 1.]]\n"
+ ]
+ }
+ ],
+ "source": [
+ "import numpy as np\n",
+ "\n",
+ "# r is the number of columns of the matrix that the elementary matrix will be multiplied to\n",
+ "def E1(i, x, r):\n",
+ " matrix = np.zeros((r,r))\n",
+ " np.fill_diagonal(matrix, 1)\n",
+ " matrix[i-1,i-1] = x\n",
+ " return matrix\n",
+ "\n",
+ "def E2(i, j, x, r):\n",
+ " if i == j:\n",
+ " raise Exception(\"i cannot be equal to j.\")\n",
+ " matrix = np.zeros((r,r))\n",
+ " np.fill_diagonal(matrix, 1)\n",
+ " matrix[i-1,j-1] = x\n",
+ " return matrix\n",
+ "\n",
+ "def E3(i, j, r):\n",
+ " if i == j:\n",
+ " raise Exception(\"i cannot be equal to j.\")\n",
+ " matrix = np.zeros((r,r))\n",
+ " np.fill_diagonal(matrix, 1)\n",
+ " matrix[i-1,j-i], matrix[j-1,i-1] = 1,1\n",
+ " matrix[i-1,i-1], matrix[j-1,j-1] = 0,0\n",
+ " return matrix\n",
+ "\n",
+ "print(E1(3,2,4))\n",
+ "print(E2(1,3,-3,3))\n",
+ "print(E3(2,3,5))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "source": [
+ "a = np.matrix([[0, 3, 1], [-2, 1, 2], [1, 0, -5]])\n",
+ "\n",
+ "a_step1 = np.matmul(E3(1, 2, a.shape[0]), a) # Multiplying E3(1,2) to A to switch rows 1 and 2.\n",
+ "a_step2 = np.matmul(E1(1, -0.5, a.shape[0]), a_step1) # Multiplying E1(1, -0.5) to A to multiply the 1st row by -0.5.\n",
+ "a_step3 = np.matmul(E2(3, 1, -1, a.shape[0]), a_step2) # Multipyling E2(3, 1,-1) to A to add -1x the 1st row to the 3rd row.\n",
+ "a_step4 = np.matmul(E1(2, 1/3, a.shape[0]), a_step3) # Multiplying E1(2, 1/3) to A to multiply the 2nd row by 1/3.\n",
+ "a_step5 = np.matmul(E2(1, 2, 0.5, a.shape[0]), a_step4) # Multipyling E2(1, 2, 0.5) to A to add 0.5x the 2nd row to the 1st row.\n",
+ "a_step6 = np.matmul(E2(3, 2, -0.5, a.shape[0]), a_step5) # Multipyling E2(3, 2, -0.5) to A to add -0.5x the 2nd row to the 3rd row.\n",
+ "a_step7 = np.matmul(E1(3, -0.24, a.shape[0]), a_step6) # Multiplying E1(3, -0.24) to A to multiply the 3rd row by -0.24\n",
+ "a_step8 = np.matmul(E2(1, 3, 5/6, a.shape[0]), a_step7) # Multipyling E2(1, 3, 5/6) to A to add 5/6x the 3rd row to the 1st row.\n",
+ "a_step9 = np.matmul(E2(2, 3, -1/3, a.shape[0]), a_step8) # Multipyling E2(1, 3, -1/3) to A to add -1/3x the 3rd row to the 2nd row.\n",
+ "print(a_step9)\n",
+ "\n",
+ "b = np.matrix([[2, 3, -1, -1], [0, -2, 1, -2], [1, 0, -2, 1]])\n",
+ "\n",
+ "b_step1 = np.matmul(E1(1, 0.5, b.shape[0]), b) # Multiplying E1(1, 0.5) to B to multiply the 1st row by 0.5.\n",
+ "b_step2 = np.matmul(E2(3, 1, -1, b.shape[0]), b_step1) # Multiplying E2(3, 1, -1) to B to add -1x the 1st row to the 3nd row.\n",
+ "b_step3 = np.matmul(E1(2, -0.5, a.shape[0]), b_step2) # Multipyling E1(2,-0.5) to B to multiply the 2nd row by -0.5.\n",
+ "b_step4 = np.matmul(E2(1, 2, -1.5, b.shape[0]), b_step3) # Multiplying E2(1, 2, -1.5) to B to add -1.5x the 2nd row to the 1st row.\n",
+ "b_step5 = np.matmul(E2(3, 2, 1.5, b.shape[0]), b_step4) # Multiplying E2(3, 2, 1.5) to B to add 1.5x the 2nd row to the 3rd row.\n",
+ "b_step6 = np.matmul(E1(3, -4/9, b.shape[0]), b_step5) # Multiplying E1(3, -4/9) to B to multiply the 3rd row by -4/9.\n",
+ "b_step7 = np.matmul(E2(1, 3, -0.25, b.shape[0]), b_step6) # Multiplying E2(1, 3, 0.25) to B to add -0.25x the 3rd row to the 1st row.\n",
+ "b_step8 = np.matmul(E2(2, 3, 0.5, b.shape[0]), b_step7) # Multiplying E2(2, 3, 0.5) to B to add 0.5x the 3rd row to the 2nd row.\n",
+ "\n",
+ "print(b_step8)\n"
+ ],
+ "metadata": {
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "id": "emIl0Bknjkzc",
+ "outputId": "c95b07d8-4546-46bf-eb9a-eb66f9904b7c"
+ },
+ "execution_count": 3,
+ "outputs": [
+ {
+ "output_type": "stream",
+ "name": "stdout",
+ "text": [
+ "[[1. 0. 0.]\n",
+ " [0. 1. 0.]\n",
+ " [0. 0. 1.]]\n",
+ "[[ 1. 0. 0. -1.66666667]\n",
+ " [ 0. 1. 0. 0.33333333]\n",
+ " [ 0. 0. 1. -1.33333333]]\n"
+ ]
+ }
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "0PZomGfxIGna"
+ },
+ "source": [
+ "## Proposition III: Solution to $A\\vec{x} = \\vec{b}$ via row reduction\n",
+ "\n",
+ "If you have a system of equations represented by the augmented matrix $[A|\\vec{b}]$, then for its row-reduced form $[\\tilde{A}|\\tilde{b}]$ and the matrix equation $A\\vec{x} = \\vec{b}$:\n",
+ "\n",
+ "1. If the row-reduced vector $\\tilde{b}$ contains a pivotal 1, then the system has _no_ solutions.\n",
+ "2. Otherwise:\n",
+ " 1. If each column of $\\tilde{A}$ has a pivotal 1, the system has a _unique_ solution.\n",
+ " 2. If at least one column of $\\tilde{A}$ is non-pivotal (i.e. doesn't have a pivotal 1), the system has _infinitely many_ solutions."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "Ey9tv2CtIGna"
+ },
+ "source": [
+ "## Example: Telling at a glance how many solutions a system of equations has\n",
+ "\n",
+ "1. Consider the system of equations:\n",
+ "\n",
+ "$$\n",
+ "\\begin{cases}\n",
+ "2x + y + 3z &= 1 \\\\\n",
+ "x - y &= 1 \\\\\n",
+ "x + y + 2z &= 1\n",
+ "\\end{cases}\n",
+ "$$\n",
+ "\n",
+ "then $[A|\\vec{b}] = \\begin{bmatrix} 2 & 1 & 3 & \\bigm| & 1 \\\\ 1 & -1 & 0 & \\bigm| & 1 \\\\ 1 & 1 & 2 & \\bigm| & 1 \\end{bmatrix}$\n",
+ "\n",
+ "which row-reduces to $[\\tilde{A}|\\tilde{b}] = \\begin{bmatrix} \\underline{1} & 0 & 1 & \\bigm| & 0 \\\\ 0 & \\underline{1} & 1 & \\bigm| & 0 \\\\ 0 & 0 & 0 & \\bigm| & \\underline{1} \\end{bmatrix}$.\n",
+ "\n",
+ "Notice that $\\tilde{b}$ contains a pivotal 1. So Proposition III tells us that the system has _no_ solutions.\n",
+ "\n",
+ "Alternatively, the last row tells us that $0 = 1$, which is a contradiction.\n",
+ "\n",
+ "2. Consider the system of equations:\n",
+ "\n",
+ "$$\n",
+ "\\begin{cases}\n",
+ "2x + y + 3z &= 1 \\\\\n",
+ "x - y &= 1 \\\\\n",
+ "x + y + 2z &= 1/3\n",
+ "\\end{cases}\n",
+ "$$\n",
+ "\n",
+ "then $[A|\\vec{b}] = \\begin{bmatrix} 2 & 1 & 3 & \\bigm| & 1 \\\\ 1 & -1 & 0 & \\bigm| & 1 \\\\ 1 & 1 & 2 & \\bigm| & 1/3 \\end{bmatrix}$\n",
+ "\n",
+ "which row-reduces to $[\\tilde{A}|\\tilde{b}] = \\begin{bmatrix} \\underline{1} & 0 & 1 & \\bigm| & 2/3 \\\\ 0 & \\underline{1} & 1 & \\bigm| & -1/3 \\\\ 0 & 0 & 0 & \\bigm| & 0 \\end{bmatrix}$.\n",
+ "\n",
+ "The row-reduced vector $\\tilde{b}$ is non-pivotal, so we know there's at least one solution.\n",
+ "\n",
+ "Next, notice that the third column is also non-pivotal.\n",
+ "\n",
+ "The first row tells us that $x + z = 2/3$; the second, that $y + z = -1/3$. So we can choose some $z$ so that all vectors of the form:\n",
+ "\n",
+ "$$\n",
+ "\\begin{bmatrix}\n",
+ "2/3 - z \\\\ -1/3 - z \\\\ z\n",
+ "\\end{bmatrix}\n",
+ "$$\n",
+ "\n",
+ "are solutions to the system. In other words, there are _infinitely many_ solutions, as Proposition III would have us believe."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "hfnLlyOmIGnb"
+ },
+ "source": [
+ "## Proposition IV: Solution to $A\\vec{x} = \\vec{b}$ via inverses\n",
+ "\n",
+ "If $A$ has an inverse $A^{-1}$, then the unique solution to $A\\vec{x} = \\vec{b}$ is given by $\\vec{x} = A^{-1}\\vec{b}$."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "M9MzR4f6IGnb"
+ },
+ "source": [
+ "## Problem 4: Prove Proposition IV.\n",
+ "\n",
+ "That is, show that $\\vec{x} = A^{-1}\\vec{b}$ solves $A\\vec{x} = \\vec{b}$ and that it is unique."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "It is already known that for any matrix $A$ that has a inverse matrix $A^{-1}$, $A^{-1}$ is unique to $A$. Therefore, all that is left to prove is that $\\vec{x} = A^{-1}\\vec{b}$ solves $A\\vec{x} = \\vec{b}$.\n",
+ "\n",
+ "It is already known that $AA^{-1} = I = A^{-1}A$, where $I$ is the identity matrix (of the same order).\n",
+ "\n",
+ "Therefore, given $A\\vec{x} = \\vec{b}$, we can multiply both sides of the equation by $A^{-1}$ on the left.\n",
+ "\n",
+ "$A^{-1}A\\vec{x} = A^{-1}\\vec{b}$\n",
+ "\n",
+ "...which simplifies to...\n",
+ "\n",
+ "$\\vec{x} = A^{-1}\\vec{b}$\n"
+ ],
+ "metadata": {
+ "id": "5NWOtMX-nIH0"
+ }
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "icOe90ZtIGnc"
+ },
+ "source": [
+ "## Proposition V: Calculating $A^{-1}$ using row reduction\n",
+ "\n",
+ "Let $A$ be an $n \\times n$ matrix. Construct the $n \\times 2n$ augmented matrix $[A|I]$ and put it in row echelon form. Then:\n",
+ "\n",
+ "1. If the first $n$ columns row-reduce to the identity, then the last $n$ columns are the inverse of $A$.\n",
+ "2. Otherwise, $A$ is not invertible."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "y3GfPN6kIGnc"
+ },
+ "source": [
+ "## Example: Computing a matrix inverse\n",
+ "\n",
+ "Let $A = \\begin{bmatrix} 2 & 1 & 3 \\\\ 1 & -1 & 1 \\\\ 1 & 1 & 2 \\end{bmatrix}$.\n",
+ "\n",
+ "Form the augmented matrix:\n",
+ "\n",
+ "$$\n",
+ "[A|I] =\n",
+ "\\begin{bmatrix}\n",
+ "2 & 1 & 3 & \\bigm| 1 & 0 & 0\\\\\n",
+ "1 & -1 & 1 & \\bigm| 0 & 1 & 0\\\\\n",
+ "1 & 1 & 2 & \\bigm| 0 & 0 & 1\n",
+ "\\end{bmatrix}\n",
+ "$$\n",
+ "\n",
+ "Row-reducing this matrix gives you:\n",
+ "\n",
+ "$$\n",
+ "\\begin{bmatrix}\n",
+ "\\underline{1} & 0 & 0 & \\bigm| & 3 & -1 & -4 \\\\\n",
+ "0 & \\underline{1} & 0 & \\bigm| & 1 & -1 & -1 \\\\\n",
+ "0 & 0 & \\underline{1} & \\bigm| & -2 & 1 & 3\n",
+ "\\end{bmatrix}\n",
+ "$$\n",
+ "\n",
+ "and so:\n",
+ "\n",
+ "$$\n",
+ "A^{-1} =\n",
+ "\\begin{bmatrix}\n",
+ "3 & -1 & -4 \\\\\n",
+ "1 & -1 & -1 \\\\\n",
+ "-2 & 1 & 3\n",
+ "\\end{bmatrix}\n",
+ "$$\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "32c8HnupIGnc"
+ },
+ "source": [
+ "## Example: Showing that $A$ has no inverse\n",
+ "\n",
+ "Let $A = \\begin{bmatrix} 2 & 1 & 3 \\\\ 1 & -1 & 0 \\\\ 1 & 1 & 2 \\end{bmatrix}$.\n",
+ "\n",
+ "Form the augmented matrix:\n",
+ "\n",
+ "$$\n",
+ "[A|I] =\n",
+ "\\begin{bmatrix}\n",
+ "2 & 1 & 3 & \\bigm| & 1 & 0 & 0\\\\\n",
+ "1 & -1 & 0 & \\bigm| & 0 & 1 & 0\\\\\n",
+ "1 & 1 & 2 & \\bigm| & 0 & 0 & 1\n",
+ "\\end{bmatrix}\n",
+ "$$\n",
+ "\n",
+ "Row-reducing this matrix gives you:\n",
+ "\n",
+ "$$\n",
+ "\\begin{bmatrix}\n",
+ "\\underline{1} & 0 & 1 & \\bigm| & 1 & 0 & -1 \\\\\n",
+ "0 & \\underline{1} & 1 & \\bigm| & -1 & 0 & 2 \\\\\n",
+ "0 & 0 & 0 & \\bigm| & -2 & 1 & 3\n",
+ "\\end{bmatrix}\n",
+ "$$\n",
+ "\n",
+ "Since the row-reduced matrix $\\tilde{A}$ on the left is not the identity matrix, $A$ is not invertible."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "ezy57ggqIGnd"
+ },
+ "source": [
+ "## Problem 5: Finding inverses\n",
+ "\n",
+ "For what values of $a$ and $b$ is the matrix $C = \\begin{bmatrix} 1 & -2 & 4 \\\\ 0 & 5 & -5 \\\\ 3 & a & b \\end{bmatrix}$ invertible?\n",
+ "\n",
+ "Calculate the inverse for those values using row reduction."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": 5,
+ "metadata": {
+ "nbgrader": {
+ "grade": true,
+ "grade_id": "cell-f25919400607a0c8",
+ "locked": false,
+ "points": 0,
+ "schema_version": 3,
+ "solution": true,
+ "task": false
+ },
+ "id": "AwaeSp4nIGnd",
+ "colab": {
+ "base_uri": "https://localhost:8080/"
+ },
+ "outputId": "ed92639f-a223-49f2-ad70-f68c9a414fac"
+ },
+ "outputs": [
+ {
+ "output_type": "execute_result",
+ "data": {
+ "text/plain": [
+ "matrix([[1, -2, 4, 1.0, 0.0, 0.0],\n",
+ " [0, 5, -5, 0.0, 1.0, 0.0],\n",
+ " [3, , , 0.0, 0.0, 1.0]],\n",
+ " dtype=object)"
+ ]
+ },
+ "metadata": {},
+ "execution_count": 5
+ }
+ ],
+ "source": [
+ "a = float\n",
+ "b = float\n",
+ "C = np.matrix([[1, -2, 4], [0, 5, -5], [3, a, b]])\n",
+ "Caug = np.hstack((C, np.identity(C.shape[1])))\n",
+ "\n",
+ "Caug\n"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "source": [
+ "Given:\n",
+ "\n",
+ "$C = \\begin{bmatrix} 1 & -2 & 4 \\\\ 0 & 5 & -5 \\\\ 3 & a & b \\end{bmatrix}$,\n",
+ "\n",
+ "$[C|I] = \\begin{bmatrix} 1 & -2 & 4 & 1 & 0 & 0 \\\\ 0 & 5 & -5 & 0 & 1 & 0 \\\\ 3 & a & b & 0 & 0 & 1\\end{bmatrix}$\n",
+ "\n",
+ "$[\\tilde{C}|\\tilde{I}] =\n",
+ "\\begin{bmatrix}\n",
+ "1 & 0 & 0 & \\frac{a + b}{a + b - 6} & 2\\frac{2a + b}{5(a + b - 6)} & \\frac{-2}{a + b - 6} \\\\\n",
+ "0 & 1 & 0 & \\frac{-3}{a + b - 6} & \\frac{b - 12}{5(a + b - 6} & \\frac{1}{a + b - 6} \\\\\n",
+ "0 & 0 & 1 & \\frac{-3}{a + b - 6} & -\\frac{a + 6}{5a + b - 6} & \\frac{1}{a + b - 6}\n",
+ "\\end{bmatrix}$\n",
+ "\n",
+ "Therefore,\n",
+ "\n",
+ "$C^{-1} =\n",
+ "\\begin{bmatrix}\n",
+ "\\frac{a + b}{a + b - 6} & 2\\frac{2a + b}{5(a + b - 6)} & \\frac{-2}{a + b - 6} \\\\\n",
+ "\\frac{-3}{a + b - 6} & \\frac{b - 12}{5(a + b - 6} & \\frac{1}{a + b - 6} \\\\\n",
+ "\\frac{-3}{a + b - 6} & -\\frac{a + 6}{5a + b - 6} & \\frac{1}{a + b - 6}\n",
+ "\\end{bmatrix}$\n",
+ "\n",
+ "Since $CC^{-1} = I$,\n",
+ "\n",
+ "$ \\begin{bmatrix} 1 & -2 & 4 \\\\ 0 & 5 & -5 \\\\ 3 & a & b \\end{bmatrix} \\begin{bmatrix}\n",
+ "\\frac{a + b}{a + b - 6} & 2\\frac{2a + b}{5(a + b - 6)} & \\frac{-2}{a + b - 6} \\\\\n",
+ "\\frac{-3}{a + b - 6} & \\frac{b - 12}{5(a + b - 6)} & \\frac{1}{a + b - 6} \\\\\n",
+ "\\frac{-3}{a + b - 6} & -\\frac{a + 6}{5a + b - 6} & \\frac{1}{a + b - 6}\n",
+ "\\end{bmatrix} = \\begin{bmatrix} 1 & 0 & 0 \\\\ 0 & 1 & 0 \\\\ 0 & 0 & 1\\end{bmatrix}$\n",
+ "\n",
+ "For the sake of calculation, I am only going to obtain $CC^{-1}_{1,1}$ and $CC^{-1}_{2,2}$.\n",
+ "\n",
+ "$ \\frac{a+b}{a+b-6} - \\frac{6}{a+b-6} = 1$\n",
+ "\n",
+ "$ \\frac{b - 12}{5(a + b - 6)} - \\frac{-a - 6}{a + b - 6} = 1$\n",
+ "\n",
+ "Any values of $a$ and $b$ fulfill the equations. Therefore, $C$ is invertible for any values of $a$ and $b$."
+ ],
+ "metadata": {
+ "id": "3YcAY7dfw4Pb"
+ }
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "qPPsgMEcIGnd"
+ },
+ "source": [
+ "---"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "MqLCkvaRIGne"
+ },
+ "source": [
+ "In practice, we don't really solve systems of equations using inverses since they're expensive to calculate. Unless otherwise stated, from this point on you may use `numpy.linalg.inv` to get the inverse of any matrix you find."
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {
+ "id": "CzLI50CDIGne"
+ },
+ "source": [
+ "## Additional resources\n",
+ "\n",
+ "* _The Geometry of Linear Equations_, an MIT OpenCourseWare lecture video by G. Strang: [LINK](https://openlearninglibrary.mit.edu/courses/course-v1:OCW+18.06SC+2T2019/courseware/d2d5b457b440451f82a3453ccc4fc28b/71a4ee751a2d42be8cc603d92f6d8dad/?child=first) (~40 mins)"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3 (ipykernel)",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.9.18"
+ },
+ "colab": {
+ "provenance": [],
+ "include_colab_link": true
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 0
+}
\ No newline at end of file