{"metadata": {"signature": "sha256:28e1cd320de3b00fe8f467d08e2eb1bddc279eed0488c7161c5f6451f1ddcb1b", "name": ""}, "worksheets": [{"metadata": {}, "cells": [{"metadata": {}, "cell_type": "markdown", "source": ["# Elimination Matrices I: The Basics"]}, {"outputs": [], "metadata": {}, "cell_type": "code", "collapsed": false, "prompt_number": 1, "language": "python", "input": ["import numpy as np"]}, {"outputs": [], "metadata": {}, "cell_type": "code", "collapsed": false, "prompt_number": 2, "language": "python", "input": ["n = 4"]}, {"metadata": {}, "cell_type": "markdown", "source": ["----------------\n", "Let's create an elimination matrix as $M$:"]}, {"outputs": [{"metadata": {}, "prompt_number": 24, "output_type": "pyout", "text": ["array([[ 1., 0., 0., 0.],\n", " [ 2., 1., 0., 0.],\n", " [ 0., 0., 1., 0.],\n", " [ 0., 0., 0., 1.]])"]}], "metadata": {}, "cell_type": "code", "collapsed": false, "prompt_number": 24, "language": "python", "input": ["M = np.eye(n)\n", "M[1,0] = 2\n", "M"]}, {"metadata": {}, "cell_type": "markdown", "source": ["Here's a matrix $A$. See if $M$ has the desired effect on $A$:"]}, {"outputs": [{"metadata": {}, "prompt_number": 19, "output_type": "pyout", "text": ["array([[ 0.4, -0.3, 2.4, -0.3],\n", " [ 0.1, 1.6, -0.9, -0.6],\n", " [ 0.2, -0.3, -1.2, -0.2],\n", " [-0.4, 0.6, -1.7, -0.7]])"]}], "metadata": {}, "cell_type": "code", "collapsed": false, "prompt_number": 19, "language": "python", "input": ["np.random.seed(5)\n", "A = np.random.randn(n, n).round(1)\n", "A"]}, {"outputs": [{"metadata": {}, "prompt_number": 20, "output_type": "pyout", "text": ["array([[ 0.4, -0.3, 2.4, -0.3],\n", " [ 0.9, 1. , 3.9, -1.2],\n", " [ 0.2, -0.3, -1.2, -0.2],\n", " [-0.4, 0.6, -1.7, -0.7]])"]}], "metadata": {}, "cell_type": "code", "collapsed": false, "prompt_number": 20, "language": "python", "input": ["M.dot(A)"]}, {"metadata": {}, "cell_type": "markdown", "source": ["-----------------------\n", "Next, see if you can build the inverse of $M$:"]}, {"outputs": [{"metadata": {}, "prompt_number": 25, "output_type": "pyout", "text": ["array([[ 1., 0., 0., 0.],\n", " [-2., 1., 0., 0.],\n", " [ 0., 0., 1., 0.],\n", " [ 0., 0., 0., 1.]])"]}], "metadata": {}, "cell_type": "code", "collapsed": false, "prompt_number": 25, "language": "python", "input": ["Minv = np.eye(n)\n", "Minv[1,0] = -2\n", "Minv"]}, {"outputs": [{"metadata": {}, "prompt_number": 26, "output_type": "pyout", "text": ["array([[ 1., 0., 0., 0.],\n", " [ 0., 1., 0., 0.],\n", " [ 0., 0., 1., 0.],\n", " [ 0., 0., 0., 1.]])"]}], "metadata": {}, "cell_type": "code", "collapsed": false, "prompt_number": 26, "language": "python", "input": ["M.dot(Minv)"]}]}], "nbformat_minor": 0, "nbformat": 3}