{"nbformat_minor": 0, "worksheets": [{"metadata": {}, "cells": [{"metadata": {}, "source": ["# Why pivoting is a good idea"], "cell_type": "markdown"}, {"prompt_number": 15, "collapsed": false, "metadata": {}, "outputs": [], "cell_type": "code", "input": ["import numpy as np\n", "import numpy.linalg as la"], "language": "python"}, {"prompt_number": 43, "collapsed": false, "metadata": {}, "outputs": [], "cell_type": "code", "input": ["\n", "A = np.array([\n", " [1e-20, 1],\n", " [1, 1],\n", "])"], "language": "python"}, {"metadata": {}, "source": ["Now find an elimination matrix and go to town:"], "cell_type": "markdown"}, {"prompt_number": 44, "collapsed": false, "metadata": {}, "outputs": [], "cell_type": "code", "input": ["U = A.copy()"], "language": "python"}, {"prompt_number": 45, "collapsed": false, "metadata": {}, "outputs": [], "cell_type": "code", "input": ["M = np.eye(2)\n", "M[1,0] = -A[1,0]/A[0,0]"], "language": "python"}, {"prompt_number": 46, "collapsed": false, "metadata": {}, "outputs": [{"prompt_number": 46, "text": ["array([[ 1.00000000e-20, 1.00000000e+00],\n", " [ 0.00000000e+00, -1.00000000e+20]])"], "metadata": {}, "output_type": "pyout"}], "cell_type": "code", "input": ["U = M.dot(U)\n", "U"], "language": "python"}, {"prompt_number": 47, "collapsed": false, "metadata": {}, "outputs": [{"prompt_number": 47, "text": ["array([[ 1.00000000e+00, 0.00000000e+00],\n", " [ -1.00000000e+20, 1.00000000e+00]])"], "metadata": {}, "output_type": "pyout"}], "cell_type": "code", "input": ["M"], "language": "python"}, {"metadata": {}, "source": ["Now define `L`:"], "cell_type": "markdown"}, {"prompt_number": 48, "collapsed": false, "metadata": {}, "outputs": [], "cell_type": "code", "input": ["L = la.inv(M)"], "language": "python"}, {"prompt_number": 49, "collapsed": false, "metadata": {}, "outputs": [{"prompt_number": 49, "text": ["array([[ 0., 0.],\n", " [ 0., -1.]])"], "metadata": {}, "output_type": "pyout"}], "cell_type": "code", "input": ["L.dot(U) - A"], "language": "python"}, {"metadata": {}, "source": ["* Problem?\n", "* Is the lower right hand entry of `U` correct?\n", "* Now try with pivoting."], "cell_type": "markdown"}]}], "metadata": {"signature": "sha256:2a5ac2fb43177a368d32a017ee4bbc6b129de6e592c1235715285500b844f502", "name": ""}, "nbformat": 3}