{ "metadata": { "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "heading", "level": 1, "metadata": {}, "source": [ "8.2.3 Gauss-Jordan with Appended System and Multiple Right-Hand Sides - Answer" ] }, { "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.3. \n", "\n", "We start with the same appended system as in 8.2.2, except now you want to add another right-hand side to the system:\n", "\n", "Let's set this up as an appended matrix and the application of a Gauss transform. Here matrix $ A $ holds the appended system\n", "$ \n", "\\left( \\begin{array}{ r r r | r r }\n", "-2 & 2 & -5 & -7 & 8 \\\\\n", "2 & -3 & 7 & 11 & -13 \\\\\n", "-4 & 3 & -7 & -9 & 9\n", "\\end{array} \\right)\n", "$\n", "\n", "Fill in the ? in matrix $ A $. Notice that if you completed notebook 8.2.2, this is the same original matrix. See what happens if you simply use the same Gauss transforms, and apply them to the appended system with the new right hand sides! " ] }, { "cell_type": "code", "collapsed": false, "input": [ "import numpy as np\n", "\n", "A = np.matrix( '-2, 2, -5, -7, 8;\\\n", " 2, -3, 7, 11,-13;\\\n", " -4, 3, -7, -9, 9' )\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 below answer to the first step in Homework 8.2.3.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 below answer to the second step in Homework 8.2.3.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.3 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 below answer to the third step in Homework 8.2.3.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.3 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 matrix in the first three columns, which then corresponds to the below answer to the fourth step in Homework 8.2.3.1:\n", "\n", " " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If you did this right, the resulting matrix represents the solution to the equations\n", "\n", " \n", "\n", "Let's see what happens if we take the two right-hand side columns and check if they solve the two equations:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "A = np.matrix( '-2, 2, -5;\\\n", " 2, -3, 7;\\\n", " -4, 3, -7' )\n", "\n", "print( 'A = ' )\n", "print( A )\n", "\n", "x0 = np.matrix( '-1;\\\n", " -2;\\\n", " 1' )\n", "\n", "x1 = np.matrix( ' 2;\\\n", " 1;\\\n", " -2' )\n", "\n", "print( 'x0 = ' )\n", "print( x0 )\n", "\n", "print( ' A * x0 = ' )\n", "print( A * x0 )\n", "\n", "print( 'x1 = ' )\n", "print( x1 )\n", "\n", "print( ' A * x1 = ' )\n", "print( A * x1 )" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Do they solve the two linear systems from homework 8.2.3.1?\n", "\n", " " ] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }