Inverting Matrices

\n", "

\n", "\n", "$$ x + y = 7 $$\n", "$$ x + 2y = 11 $$\n", "\n", "

\n", "

\n", "\n", "To solve for a system of equations, we must have as many equations as unknowns. The idea is to leverage the equations to isolate values for the unknowns. \n", "\n", "Three potential outcomes:\n", "\n", "1. We'll find many solutions (potentially an infinite number of solutions for potential values of $x$ and $y$\n", "2. We'll find one solution.\n", "3. We'll find no solution. \n", "\n", "Essentially, we are trying to locate the point (or set of points) where these two lines intersect.\n", "\n", "> Note: The far deeper discussion on how solve a system of linear equations is covered in the reading." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's solve the above system. \n", "\n", "\\begin{equation}\n", "x + y = 7\\\\\n", "x + 2y = 11\n", "\\end{equation}\n", "\n", "

\n", "

\n", "\n", "\\begin{equation}\n", "x = 7 - y \\\\\n", "x + 2y = 11\n", "\\end{equation}\n", "\n", "

\n", "

\n", "\n", "\\begin{equation}\n", "x = 7 - y \\\\\n", "(7 - y) + 2y = 11\n", "\\end{equation}\n", "\n", "

\n", "

\n", "\n", "\\begin{equation}\n", "x = 7 - y \\\\\n", "y = 4\n", "\\end{equation}\n", "\n", "

\n", "

\n", "\n", "\\begin{equation}\n", "x = 7 - (4) \\\\\n", "y = 4\n", "\\end{equation}\n", "\n", "

\n", "

\n", "\n", "\\begin{equation}\n", "x = 3 \\\\\n", "y = 4\n", "\\end{equation}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's plug these values back in to get see if they work.\n", "\n", "\\begin{equation}\n", "(3) + (4) = 7\\\\\n", "(3) + 2(4) = 11\n", "\\end{equation}\n", "\n", "Looks good!" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## System of Linear Equations in Matrix Form" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

\n", "

\n", "\n", "\\begin{equation}\n", "1x + 1y = 7\\\\\n", "1x + 2y = 11\n", "\\end{equation}\n", "\n", "

\n", "

\n", "\n", "\\begin{equation}\n", "\\begin{bmatrix}\n", "1 & 1\\\\ 1 & 2\n", "\\end{bmatrix}\n", "\\begin{bmatrix}\n", "x \\\\ y\n", "\\end{bmatrix} = \n", "\\begin{bmatrix}\n", "7 \\\\ 11\n", "\\end{bmatrix}\n", "\\end{equation}\n", "\n", "

\n", "

\n", "\n", "\\begin{equation}\n", "\\textbf{A} \\textbf{b} = \\textbf{y}\n", "\\end{equation}\n", "\n", "Where:\n", "\n", "- $\\textbf{A}$ can be thought of as our data\n", "- $\\textbf{b}$ can be thought of as our unknown coefficients\n", "- $\\textbf{y}$ can be thought of as our outcomes for which we are trying to solve for\n", "\n", "

\n", "

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can express this matrix as an \"**augmented matrix**\" (which will help as we perform row-wise operations)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

\n", "

\n", "\n", "\\begin{equation}\n", "\\left|\n", "\\begin{array}{cc|c}\n", "1 & 1 & 7 \\\\ \n", "1 & 2 & 11 \\\\ \n", "\\end{array}\n", "\\right|\n", "\\end{equation}\n", "\n", "

\n", "

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Reduced Row Echelon Form (rref)\n", "\n", "The goal of RREF is to use row-wise addition/subtraction and scaling to reduce each column so that 1 of the row entries equals one and the rest of the entries equal 0.\n", "\n", "In essence, we want $\\textbf{A}$ to resemble $\\textbf{I}$.\n", "\n", "

\n", "

\n", "\n", "\\begin{equation}\n", "\\begin{bmatrix}\n", "1 & 1\\\\ 1 & 2\n", "\\end{bmatrix}\n", "\\rightarrow\n", "\\begin{bmatrix}\n", "1 & 0\\\\ 0 & 1\n", "\\end{bmatrix}\n", "\\end{equation}\n", "\n", "

\n", "

\n", "\n", "Why might we want to do this? \n", "\n", "\n", "Recall, if we think of matrix multiplication as a linear transformation (as we did last time), we'll remember that we're really fundamentally changing those unit vectors into a new coordinate system (e.g. $c_1\\textbf{A}\\hat{i} + c_2\\textbf{A}\\hat{j}$). The aim here is to reverse that process. That is, what steps do we need to take to go _back_ to our original unit vectors ($\\hat{i},\\hat{j}$).\n", "\n", "\n", "

\n", "

\n", "\n", "We can do this as we did before (i.e. when writing a function that would do the transformation for us) by performing the row-wise operations on both sides of the augmented matrix. The result will be the solution to our linear equation (if a solution exists). \n", "\n", "> Again, this is a simplification of rref and solving for systems of equations. Check out the reading for a more involved discussion. The point is to get the intuition of what is going on here." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

\n", "

\n", "\n", "\\begin{equation}\n", "\\left|\n", "\\begin{array}{cc|c}\n", "1 & 1 & 7 \\\\ \n", "1 & 2 & 11 \\\\ \n", "\\end{array}\n", "\\right|\n", "\\end{equation}\n", "\n", "

\n", "

\n", "\n", "Hold the first row fixed. How do we get position (2,1) in the matrix to be zero? Subtract the first row from the second.\n", "\n", "

\n", "

\n", "\n", "\\begin{equation}\n", "\\left|\n", "\\begin{array}{cc|c}\n", "1 & 1 & 7 \\\\ \n", "1 - 1 & 2 - 1 & 11 - 7 \\\\ \n", "\\end{array}\n", "\\right|\n", "\\end{equation}\n", "\n", "

\n", "

\n", "\n", "\\begin{equation}\n", "\\left|\n", "\\begin{array}{cc|c}\n", "1 & 1 & 7 \\\\ \n", "0 & 1 & 4 \\\\ \n", "\\end{array}\n", "\\right|\n", "\\end{equation}\n", "\n", "

\n", "

\n", "\n", "Holding the second row fixed. How do we get position (1,2) in the matrix to be zero? Subtract the second row from the first.\n", "\n", "

\n", "

\n", "\n", "\\begin{equation}\n", "\\left|\n", "\\begin{array}{cc|c}\n", "1-0 & 1-1 & 7-4 \\\\ \n", "0 & 1 & 4 \\\\ \n", "\\end{array}\n", "\\right|\n", "\\end{equation}\n", "\n", "\n", "

\n", "

\n", "\n", "\\begin{equation}\n", "\\left|\n", "\\begin{array}{cc|c}\n", "1 & 0 & 3 \\\\ \n", "0 & 1 & 4 \\\\ \n", "\\end{array}\n", "\\right|\n", "\\end{equation}\n", "\n", "\n", "

\n", "

\n", "\n", "**We've found our solution!**" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's check it.\n", "\n", "\n", "\\begin{equation}\n", "\\begin{bmatrix}\n", "1 & 1\\\\ 1 & 2\n", "\\end{bmatrix}\n", "\\begin{bmatrix}\n", "3 \\\\ 4\n", "\\end{bmatrix} = \n", "\\begin{bmatrix}\n", "1(3) + 1(4)\\\\ 1(3) + 2(4)\n", "\\end{bmatrix} =\n", "\\begin{bmatrix}\n", "7 \\\\ 11\n", "\\end{bmatrix}\n", "\\end{equation}" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 7, 11])" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A = np.array([[1,1],[1,2]])\n", "x = np.array([3,4])\n", "b = A.dot(x)\n", "b" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### RREF as a matrix transformation\n", "\n", "We can encode these instructions to reduce the data down as a matrix transformation (just as we did when we first introduced matrices). We'll perform our instructions on the identity matrix, $\\textbf{I}$, like we did before. \n", "\n", "

\n", "

\n", "\n", "Again, our instructions (i.e. the steps we took above):\n", "\n", "

\n", "

\n", "\n", "1. Hold the first row constant and subtract the first row from the second row\n", "\n", "

\n", "

\n", "\n", "$$ f_1(x) = \\begin{bmatrix} x_1\\\\x_2 - x_1\\end{bmatrix} $$\n", "\n", "

\n", "

\n", "\n", "2. Hold the second row constant and subtract the second row from the first row\n", "\n", "

\n", "

\n", "\n", "$$ f_2(x) = \\begin{bmatrix} x_1 - x_2 \\\\x_2\\end{bmatrix} $$\n", "\n", "

\n", "

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Let's perform these operations on our identity matrix.\n", "\n", "

\n", "

\n", "\n", "$$\\textbf{I} = \\begin{bmatrix}\n", "1 & 0\\\\ 0 & 1\n", "\\end{bmatrix}$$\n", "\n", "

\n", "

\n", "\n", "\\begin{equation}\n", "f_1(\\textbf{I}) = \\begin{bmatrix} 1 & 0\\\\0-1 & 1-0\\end{bmatrix} = \\begin{bmatrix} 1 & 0\\\\-1 & 1\\end{bmatrix}\n", "\\end{equation}\n", "\n", "

\n", "

\n", "\n", "\\begin{equation}\n", "f_2(\\begin{bmatrix} 1 & 0\\\\-1 & 1\\end{bmatrix}) = \\begin{bmatrix} 1-(-1) & 0-1 \\\\-1 & 1\\end{bmatrix}= \\begin{bmatrix} 2 & -1\\\\-1 & 1\\end{bmatrix} \n", "\\end{equation}\n", "\n", "

\n", "

\n", "\n", "\n", "\\begin{equation}\n", "\\begin{bmatrix} 2 & -1\\\\-1 & 1\\end{bmatrix} \n", "\\end{equation}" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "What is this matrix? It's the inverse of matrix $\\textbf{A}$! \n", "\n", "\n", "

\n", "

\n", "\n", "$$\\textbf{A} = \\begin{bmatrix}1 & 1\\\\ 1 & 2\\end{bmatrix}$$\n", "\n", "

\n", "

\n", "\n", "$$\\textbf{A}^{-1} = \\begin{bmatrix} 2 & -1\\\\-1 & 1\\end{bmatrix}$$\n", "\n", "\n", "

\n", "

\n", "\n", "We can use this inverse transformation to take our vector **_back_** to where we started. \n", "\n", "

\n", "

\n", "\n", "\n", "\\begin{equation}\n", "\\textbf{A}^{-1}\\textbf{y} = \\begin{bmatrix} 2 & -1\\\\-1 & 1\\end{bmatrix} \\begin{bmatrix}7\\\\11\\end{bmatrix} = \\begin{bmatrix}3\\\\4\\end{bmatrix} = \\textbf{b}\n", "\\end{equation}\n", "\n", "

\n", "

\n", "\n", "\\begin{equation}\n", "\\textbf{A}\\textbf{x} = \\begin{bmatrix}1 & 1\\\\ 1 & 2\\end{bmatrix} \\begin{bmatrix}3\\\\4\\end{bmatrix} = \\begin{bmatrix}7\\\\11\\end{bmatrix} = \\textbf{y}\n", "\\end{equation}\n", "\n", "

\n", "

\n", "\n", "We can think of the inverse transformation as numerical instructions to solve for a system of linear equations!\n" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Our first tranformation matrix\n", "\n", "[[ 1 0]\n", " [-1 1]]\n", "\n", "Our second tranformation matrix\n", "\n", "[[ 1 -1]\n", " [ 0 1]]\n" ] } ], "source": [ "T1 = np.array([[1,0],[-1,1]])\n", "print(\"Our first tranformation matrix\\n\")\n", "print(T1)\n", "T2 = np.array([[1,-1],[0,1]])\n", "print(\"\\nOur second tranformation matrix\\n\")\n", "print(T2)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [], "source": [ "# together\n", "A_inv = T2.dot(T1)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([ 7, 11])" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "b" ] }, { "cell_type": "code", "execution_count": 6, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([3, 4])" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A_inv.dot(b)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And where $\\textbf{A}$ dotted with its inverse $\\textbf{A}^{-1}$ transforms us back to $\\textbf{I}$" ] }, { "cell_type": "code", "execution_count": 7, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[1, 0],\n", " [0, 1]])" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A_inv.dot(A)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Invertible Functions" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note (or recall) that we can only solve for a system where there is as many equations as there are unknowns." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

\n", "

\n", "\n", "We _cannot_ solve this...\n", "\\begin{equation}\n", "x + y - 3z = -10\\\\\n", "x - y + 2z = 3\n", "\\end{equation}\n", "\n", "

\n", "

\n", "\n", "But we could potentially solve this...\n", "\n", "\\begin{equation}\n", "x + y - 3z = -10\\\\\n", "x - y + 2z = 3 \\\\\n", "2x + y - z = -6 \n", "\\end{equation}\n", "\n", "

\n", "

\n", "\n", "What does this mean for us in linear algebra land?\n", "\n", "$$ \\begin{bmatrix} 1 & 1 & -3 \\\\1 & -1 & 2 \\\\ 2 & 1 & -1\\end{bmatrix} \\begin{bmatrix} x\\\\y\\\\z\\end{bmatrix} = \\begin{bmatrix} -10\\\\2\\\\-6\\end{bmatrix} $$\n", "\n", "

\n", "

\n", "\n", "The matrix we are inverting must always be a **square matrix**. That is, **_the rank of the column space must be equal to the rank of the row space._** \n", "\n", "This is just a fancy way of saying that none of the column vectors are a linear combination of another column vector, i.e. they are linearly independent. And likewise with the row vectors.\n", "\n", "

\n", "

\n", "\n", "$$ Rank(colspace(\\textbf{A})) = Rank(rowspace(\\textbf{A}))$$\n", "\n", "\n", "$$ N~Cols = N~Rows$$\n", "\n", "

\n", "

\n", "\n", "Another way to think about this, if a matrix transformation reduces a vector or matrix into a lower dimension (dimension reduction), then we can't walk back to where we started. **_Dimension reduction always results in a loss of information._**\n", "\n", "

\n", "

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "More generally, let's thinking about what it means to **_invert a function_**. \n", "\n", "

\n", "

\n", "\n", "$$ f: x \\mapsto y $$\n", "\n", "

\n", "

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "An inverse function takes us **back** from our codomain $y$ to our original domain $x$ \n", "\n", "

\n", "

\n", "\n", "$$ f^{-1}: y \\mapsto x $$\n", "\n", "

\n", "

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " But we can only do this for a function that is **surjective** and **injective**. \n", " \n", "

\n", "

\n", "\n", "- **surjective**: there exists a mapping for every value of set $\\textbf{x}$ \"onto\" set $\\textbf{y}$. That is, every value from one set maps onto a value in the other set.\n", "\n", "\n", "```\n", "Surjective!\n", "\n", " X Y\n", " - -\n", " a => z\n", " b => y\n", " c => x\n", " d => x\n", "\n", "Not Surjective\n", " X Y\n", " - -\n", " a => z\n", " b => y\n", " c => x\n", " d \n", "```\n", "\n", "

\n", "

\n", "\n", "- **injective**: there exists a \"one-to-one\" mapping of values in set $\\textbf{x}$ onto set $\\textbf{y}$. That is. there exists a unique mapping for each $\\textbf{x}$ onto $\\textbf{y}$\n", "\n", "```\n", "Injective!\n", "\n", " X Y\n", " - -\n", " a => z\n", " b => y\n", " c => x\n", " d => w\n", "\n", "Not injective\n", " X Y\n", " - -\n", " a => z\n", " b => y\n", " c => x\n", " d => x\n", "```\n", "\n", "**The idea is that every value of $x$ maps onto a unique value of $y$.** If we don't have sufficient information, that is, if we don't have equal number of dimensions, then the function wouldn't be surjective and we can't invert." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### What to do if our matrix isn't square?\n", "\n", "Recall from the last lecture that we can _always generate a square matrix by projecting it back onto itself_ by squaring it. " ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(5, 3)" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "B = np.random.randn(5,3)\n", "B.shape" ] }, { "cell_type": "code", "execution_count": 9, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(5, 5)" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "B.dot(B.T).shape" ] }, { "cell_type": "code", "execution_count": 10, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(3, 3)" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "B.T.dot(B).shape" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## How to determine if a matrix is invertible" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Recall above that we encoded instructions regarding how to convert a $2 \\times 2$ matrix into RREF. \n", "\n", "Let's follow those steps again but this time on a more general representation of the matrix." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "

\n", "

\n", "\n", "\\begin{equation}\n", "\\textbf{A} = \n", "\\begin{bmatrix}\n", "a & b \\\\ c & d\n", "\\end{bmatrix} = \n", "\\begin{bmatrix}\n", "R_1 \\\\ R_2\n", "\\end{bmatrix}\n", "\\end{equation}\n", "\n", "

\n", "

\n", "\n", "Let's put it in augmented matrix form, and perform our row-wise manipulations simultaneously on $\\textbf{I}$\n", "\n", "

\n", "

\n", "\n", "\\begin{equation}\n", "\\left|\n", "\\begin{array}{cc|cc}\n", "a & b & 1 & 0 \\\\ \n", "c & d & 0 & 1 \\\\ \n", "\\end{array}\n", "\\right|\n", "\\end{equation}\n", "\n", "\n", "

\n", "

\n", "\n", "**Transformation 1**:\n", "\n", "

\n", "

\n", "\n", "\\begin{equation}\n", "\\textbf{T}_1 = \n", "\\begin{bmatrix}\n", "R_1 \\\\ aR_2 - cR_1\n", " \\end{bmatrix}\n", "\\end{equation}\n", "\n", "\n", "

\n", "

\n", "\n", "\\begin{equation}\n", "\\left|\n", "\\begin{array}{cc|cc}\n", "a & b & 1 & 0 \\\\ \n", "0 & ad - bc & -c & a \\\\ \n", "\\end{array}\n", "\\right|\n", "\\end{equation}\n", "\n", "

\n", "

\n", "\n", "**Transformation 2**:\n", "\n", "

\n", "

\n", "\n", "\\begin{equation}\n", "\\textbf{T}_2 = \n", "\\begin{bmatrix}\n", "(ad-bc)R_1 - bR_2 \\\\ R_2 \n", " \\end{bmatrix}\n", "\\end{equation}\n", "\n", "

\n", "

\n", "\n", "\\begin{equation}\n", "\\left|\n", "\\begin{array}{cc|cc}\n", "a(ad-bc) & 0 & ad & -ab \\\\ \n", "0 & ad - bc & -c & a \\\\ \n", "\\end{array}\n", "\\right|\n", "\\end{equation}\n", "\n", "

\n", "

\n", "\n", "**Transformation 3**: ensure the diagonals equal 1\n", "\n", "

\n", "

\n", "\n", "\\begin{equation}\n", "\\textbf{T}_3 = \n", "\\begin{bmatrix}\n", "\\frac{R_1}{a(ad-bc)} \\\\ \\frac{R_2}{(ad-bc)}\n", " \\end{bmatrix}\n", "\\end{equation}\n", "\n", "

\n", "

\n", "\n", "\\begin{equation}\n", "\\left|\n", "\\begin{array}{cc|cc}\n", "1 & 0 & \\frac{d}{(ad-bc)} & \\frac{-b}{(ad-bc)} \\\\ \n", "0 & 1 & \\frac{-c}{(ad-bc)} & \\frac{a}{(ad-bc)} \\\\ \n", "\\end{array}\n", "\\right|\n", "\\end{equation}\n", "\n", "

\n", "

\n", "\n", "This yields the formula for the inverse of a $2 \\times 2 $ matrix.\n", "\n", "

\n", "

\n", "\n", "\\begin{equation}\n", "\\frac{1}{ad-bc}\n", "\\begin{bmatrix}\n", "d & -b \\\\ -c & a\n", " \\end{bmatrix}\n", "\\end{equation}\n", "\n", "

\n", "

\n", "\n", "What is $ad-bc$?\n", "\n", "

\n", "

" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### The Determinant\n", "\n", "

\n", "

\n", "\n", "$$ det(\\textbf{A}) = |\\textbf{A}| = ad-bc $$\n", "\n", "

\n", "

\n", "\n", "The determinant of matrix $\\textbf{A}$ tells us if a (square) matrix is invertible. When we examine the above equation, it's obvious why this is. A fraction with a denominator of $0$ is undefined, meaning we can't solve it. \n", "\n", "But what does this actually mean? \n", "\n", "It means that the vectors composing the square matrix are **_not_ linearly independent**." ] }, { "cell_type": "code", "execution_count": 11, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([[1, 2],\n", " [2, 4]])" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "A = np.array([[1,2],[2,4]])\n", "A" ] }, { "cell_type": "code", "execution_count": 12, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "0.0" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.linalg.det(A)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "To give a better intuition of what is going on, think of the determinant as the **area of a square** (when in $\\Re^2$) generated by our two basis vectors. When we transform these vectors, that area grows and shrinks. When that area goes to zero, it means that we've collapsed to a lower dimension (i.e. down to a line if we were in $\\Re^2$). Thus, the determinant tells us if there is sufficient information in the matrix to take us back to where we started (i.e. if the column and row space of our square matrix are actually linearly independent). \n", "\n", "[Here is a great video](https://www.youtube.com/watch?v=Ip3X9LOh2dk&vl=en) that outlines how we can think of the determinant of a matrix in $\\Re^2$ as the area of a square. \n", "\n", "Note that when the determinant of a matrix is 0 we call it **singular**." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "> NOTE: that finding the determinant for an $n \\times n$ matrix is more involved! See the reading for a deeper discussion on this. We'll be relying on our computers to compute these values, but it's useful to have a deeper understanding of the steps. " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Which of these matrices are invertible?" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[[14 -7]\n", " [ 2 -1]] \n", "\n", "[[-1.31692334 -0.44108299 0.56100078 0.93984351 2.24174342]\n", " [-0.62457184 -0.16588639 0.14610647 -1.78707646 -0.05134602]\n", " [ 0.57006418 -0.31545966 0.03206903 1.0371645 0.23118344]\n", " [-1.00540481 1.65994245 -0.26802636 0.90013057 -0.13122613]] \n", "\n", "[[0 0 0 0]\n", " [1 0 0 1]\n", " [0 1 0 0]] \n", "\n" ] } ], "source": [ "X = np.array([[14,-7],[2,-1]])\n", "Y = np.random.randn(4,5)\n", "Z = np.array([[0,0,0,0],\n", " [1,0,0,1],\n", " [0,1,0,0]])\n", "print(X,\"\\n\")\n", "print(Y,\"\\n\")\n", "print(Z,\"\\n\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.7.0" }, "toc": { "base_numbering": 1, "nav_menu": {}, "number_sections": false, "sideBar": false, "skip_h1_title": false, "title_cell": "Table of Contents", "title_sidebar": "Contents", "toc_cell": false, "toc_position": {}, "toc_section_display": true, "toc_window_display": false } }, "nbformat": 4, "nbformat_minor": 2 }