{ "metadata": { "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "8.2.4 Gauss-Jordan with Appended System to Invert a Matrix" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ " Copy this notebook first! At each step, if you make a mistake, rerun all the cells above the current cell!!!\n", "\n", "
\n", "\n", "With this notebook, we walk you through Homework 8.2.4. \n", "\n", "We start with the same appended system as in 8.2.4, except now we work with three right-hand sides, and pick those right-hand sides to be the unit basis vectors. In other words, we append the identity matrix.\n", "\n", "Let's set this up as an appended matrix and the application of Gauss transforms. Here matrix $ A $ holds the appended system\n", "$ \n", "\\left( \\begin{array}{ r r r | r r f}\n", "-2 & 2 & -5 & 1 & 0 & 0 \\\\\n", "2 & -3 & 7 & 0 & 1 & 0 \\\\\n", "-4 & 3 & -7 & 0 & 0 & 1\n", "\\end{array} \\right)\n", "$\n", "\n", "Fill in the ? in matrix $ A $. Notice that the matrix on the left side of the appended system is the same as the matrix from 8.2.2 and 8.2.3. See what happens if you simply use the same Gauss transforms, and apply them to the appended system! " ] }, { "cell_type": "code", "collapsed": false, "input": [ "import numpy as np\n", "\n", "A = np.matrix( '-2, 2, -5, 1, 0, 0;\\\n", " 2, -3, 7, 0, 1, 0;\\\n", " -4, 3, -7, 0, 0, 1' )\n", "\n", "print( 'A = ' )\n", "print( A )\n", "\n", "G0 = np.matrix( ' 1, 0, 0;\\\n", " 1, 1, 0;\\\n", " -2, 0, 1' );\n", "\n", "A0 = G0 * A\n", "\n", "print( 'A0 = ' )\n", "print( A0 )" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you did this right, the result matrix $ A_0 = G_0 A $ has zeroes in the off-diagonal entries of the first column, which then corresponds to the answer to the first step in Homework 8.2.4.1:\n", "\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The appended system is now represented by A0 :" ] }, { "cell_type": "code", "collapsed": false, "input": [ "print( 'A0 =' )\n", "print( A0 )" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, use $ G_1 $ from Homework 8.2.2.1 to introduce zeroes in the off-diagonal elemental of the second column of $ A_0 $:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "G1 = np.matrix( ' 1, 2, 0;\\\n", " 0, 1, 0;\\\n", " 0, -1, 1' );\n", "\n", "A1 = G1 * A0\n", "\n", "print( 'A1 = ' )\n", "print( A1 )" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you did this right, the result matrix $ A_1 = G_1 A_0 = G_1 G_0 A $ has zeroes in the off-diagonal entries of the first column and the second column, which then corresponds to the answer to the second step in Homework 8.2.4.1:\n", "\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The appended system is now represented by A1 :" ] }, { "cell_type": "code", "collapsed": false, "input": [ "print( 'A1 =' )\n", "print( A1 )" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, use the $ G_2 $ from Homework 8.2.2 to introduce zeroes in the off-diagonal elemental of the third column of $ A_1 $:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "G2 = np.matrix( ' 1, 0, 1;\\\n", " 0, 1, -2;\\\n", " 0, 0, 1' );\n", "\n", "A2 = G2 * A1\n", "\n", "print( 'A2 = ' )\n", "print( A2 )" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you did this right, the result matrix $ A_2 = G_2 A_1 = G_2 G_1 A_0 = G_2 G_1 G_0 A $ has zeroes in the off-diagonal entries of the first, second, and third column, which then corresponds to the answer to the third step in Homework 8.2.4.1:\n", "\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The appended system is now represented by A2 :" ] }, { "cell_type": "code", "collapsed": false, "input": [ "print( 'A2 =' )\n", "print( A2 )" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Now, use the diagonal matrix $ D $ from Homework 8.2.2 to set the diagonal elements in the appended system to one, making the first three columns into an identity matrix:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "D = np.matrix( '-0.5, 0, 0;\\\n", " 0, -1, 0;\\\n", " 0, 0, 1' );\n", "\n", "A3 = D * A2\n", "\n", "print( 'A3 = ' )\n", "print( A3 )" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you did this right, the result matrix \n", "\n", "$ A_3 = D A_2 = D G_2 A_1 = D G_2 G_1 A_0 = D G_2 G_1 G_0 A $ \n", "\n", "has an identity in the first three columns, which then corresponds to the answer to the fourth step in Homework 8.2.4.1:\n", "\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you did this right, the last three columns of the appended system now contain the inverse of the original matrix $ A $.\n", "\n", "Let's see what happens if we create a matrix $ B $ from the last three columns, restore the matrix $ A $ to its original contents, and multiply $ A B $:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "B = A3[ 0:3, 3:6 ]\n", "\n", "print( 'B = ' )\n", "print( B )\n", "\n", "A = np.matrix( '-2, 2, -5;\\\n", " 2, -3, 7;\\\n", " -4, 3, -7' )\n", "\n", "print( 'A = ' )\n", "print( A )\n", "\n", "print( 'B = ' )\n", "print( B )\n", "\n", "print( ' A * B = ' )\n", "print( A * B )" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Hopefully, yielded the answer to the last part of 8.2.4.1:\n", "\n", " " ] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }