{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Behavior of Elimination Matrices" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": false }, "outputs": [], "source": [ "import numpy as np" ] }, { "cell_type": "code", "execution_count": 30, "metadata": { "collapsed": false }, "outputs": [], "source": [ "n = 4" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "----------------\n", "Let's create some elimination matrices:" ] }, { "cell_type": "code", "execution_count": 40, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "array([[ 1. , 0. , 0. , 0. ],\n", " [ 0.5, 1. , 0. , 0. ],\n", " [ 0. , 0. , 1. , 0. ],\n", " [ 0. , 0. , 0. , 1. ]])" ] }, "execution_count": 40, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M1 = np.eye(n)\n", "M1[1,0] = 0.5\n", "M1" ] }, { "cell_type": "code", "execution_count": 41, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "array([[ 1., 0., 0., 0.],\n", " [ 0., 1., 0., 0.],\n", " [ 0., 0., 1., 0.],\n", " [ 4., 0., 0., 1.]])" ] }, "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M2 = np.eye(n)\n", "M2[3,0] = 4\n", "M2" ] }, { "cell_type": "code", "execution_count": 42, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "array([[ 1. , 0. , 0. , 0. ],\n", " [ 0. , 1. , 0. , 0. ],\n", " [ 0. , 1.3, 1. , 0. ],\n", " [ 0. , 0. , 0. , 1. ]])" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M3 = np.eye(n)\n", "M3[2,1] = 1.3\n", "M3" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "-------------------\n", "Now play around with them:" ] }, { "cell_type": "code", "execution_count": 43, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "array([[ 1. , 0. , 0. , 0. ],\n", " [ 0.5, 1. , 0. , 0. ],\n", " [ 0. , 0. , 1. , 0. ],\n", " [ 4. , 0. , 0. , 1. ]])" ] }, "execution_count": 43, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M1.dot(M2)" ] }, { "cell_type": "code", "execution_count": 44, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "array([[ 1. , 0. , 0. , 0. ],\n", " [ 0.5, 1. , 0. , 0. ],\n", " [ 0. , 0. , 1. , 0. ],\n", " [ 4. , 0. , 0. , 1. ]])" ] }, "execution_count": 44, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M2.dot(M1)" ] }, { "cell_type": "code", "execution_count": 45, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "array([[ 1. , 0. , 0. , 0. ],\n", " [ 0.5, 1. , 0. , 0. ],\n", " [ 0. , 1.3, 1. , 0. ],\n", " [ 4. , 0. , 0. , 1. ]])" ] }, "execution_count": 45, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M1.dot(M2).dot(M3)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "BUT:" ] }, { "cell_type": "code", "execution_count": 47, "metadata": { "collapsed": false }, "outputs": [ { "data": { "text/plain": [ "array([[ 1. , 0. , 0. , 0. ],\n", " [ 0.5 , 1. , 0. , 0. ],\n", " [ 0.65, 1.3 , 1. , 0. ],\n", " [ 4. , 0. , 0. , 1. ]])" ] }, "execution_count": 47, "metadata": {}, "output_type": "execute_result" } ], "source": [ "M3.dot(M1).dot(M2)" ] } ], "metadata": {}, "nbformat": 4, "nbformat_minor": 0 }