{"metadata": {"signature": "sha256:ef423c670af97e2e4421195e937d9a6c3accb1a75e6970e4b8e190ee48e567e9", "name": ""}, "nbformat_minor": 0, "nbformat": 3, "worksheets": [{"metadata": {}, "cells": [{"metadata": {}, "cell_type": "markdown", "source": ["# Gaussian elimination"]}, {"outputs": [], "prompt_number": 3, "language": "python", "cell_type": "code", "metadata": {}, "collapsed": false, "input": ["import numpy as np"]}, {"outputs": [{"metadata": {}, "text": ["array([[ 2., -2., 12., -1.],\n", " [ 1., 8., -5., -3.],\n", " [ 1., -2., -6., -1.],\n", " [ -2., 3., -8., -4.]])"], "prompt_number": 18, "output_type": "pyout"}], "prompt_number": 18, "language": "python", "cell_type": "code", "metadata": {}, "collapsed": false, "input": ["\n", "np.random.seed(5)\n", "n = 4\n", "A = np.round(np.random.randn(n, n) * 5)\n", "A"]}, {"metadata": {}, "cell_type": "markdown", "source": ["Now compute `A1` to eliminate `A[1,0]`:"]}, {"outputs": [{"metadata": {}, "text": ["array([[ 2. , -2. , 12. , -1. ],\n", " [ 0. , 9. , -11. , -2.5],\n", " [ 1. , -2. , -6. , -1. ],\n", " [ -2. , 3. , -8. , -4. ]])"], "prompt_number": 23, "output_type": "pyout"}], "prompt_number": 23, "language": "python", "cell_type": "code", "metadata": {}, "collapsed": false, "input": ["A1 = A.copy()\n", "A1[1] -= 1/2*A1[0]\n", "A1"]}, {"metadata": {}, "cell_type": "markdown", "source": ["And `A2` with `A[2,0] == 0`:"]}, {"outputs": [{"metadata": {}, "text": ["array([[ 2. , -2. , 12. , -1. ],\n", " [ 0. , 9. , -11. , -2.5],\n", " [ 0. , -1. , -12. , -0.5],\n", " [ -2. , 3. , -8. , -4. ]])"], "prompt_number": 25, "output_type": "pyout"}], "prompt_number": 25, "language": "python", "cell_type": "code", "metadata": {}, "collapsed": false, "input": ["A2 = A1.copy()\n", "A2[2] -= 1/2*A[0]\n", "A2"]}, {"outputs": [], "language": "python", "cell_type": "code", "metadata": {}, "collapsed": false, "input": []}]}]}