{ "metadata": { "name": "" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "collapsed": false, "input": [ "import numpy as np\n", "import scipy.linalg as la" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stderr", "text": [ "/usr/lib/pymodules/python2.7/numpy/oldnumeric/__init__.py:11: ModuleDeprecationWarning: The oldnumeric module will be dropped in Numpy 1.9\n", " warnings.warn(_msg, ModuleDeprecationWarning)\n" ] } ], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "n = 6\n", "\n", "np.random.seed(0)\n", "A = (\n", " + np.diag(np.random.randn(n))\n", " + np.roll(np.diag(np.random.randn(n)), 1)\n", " + np.roll(np.diag(np.random.randn(n)), -1)\n", " )\n", "\n", "np.set_printoptions(precision=2)\n", "A" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 2, "text": [ "array([[ 3.22, 0.95, 0. , 0. , 0. , 0. ],\n", " [ 0.12, 0.4 , -0.15, 0. , 0. , 0. ],\n", " [ 0. , 0.44, 0.98, -0.1 , 0. , 0. ],\n", " [ 0. , 0. , 0.33, 2.24, 0.41, 0. ],\n", " [ 0. , 0. , 0. , 1.49, 1.87, 0.14],\n", " [ 0. , 0. , 0. , 0. , -0.21, -0.22]])" ] } ], "prompt_number": 2 }, { "cell_type": "code", "collapsed": false, "input": [ "P, L, U = la.lu(A)" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 3 }, { "cell_type": "code", "collapsed": false, "input": [ "L" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 4, "text": [ "array([[ 1. , 0. , 0. , 0. , 0. , 0. ],\n", " [ 0. , 1. , 0. , 0. , 0. , 0. ],\n", " [ 0.04, 0.82, 1. , 0. , 0. , 0. ],\n", " [ 0. , 0. , -0.35, 1. , 0. , 0. ],\n", " [ 0. , 0. , -0. , 0.66, 1. , 0. ],\n", " [ 0. , 0. , -0. , 0. , -0.13, 1. ]])" ] } ], "prompt_number": 4 }, { "cell_type": "code", "collapsed": false, "input": [ "U" ], "language": "python", "metadata": {}, "outputs": [ { "metadata": {}, "output_type": "pyout", "prompt_number": 5, "text": [ "array([[ 3.22, 0.95, 0. , 0. , 0. , 0. ],\n", " [ 0. , 0.44, 0.98, -0.1 , 0. , 0. ],\n", " [ 0. , 0. , -0.95, 0.08, 0. , 0. ],\n", " [ 0. , 0. , 0. , 2.27, 0.41, 0. ],\n", " [ 0. , 0. , 0. , 0. , 1.6 , 0.14],\n", " [ 0. , 0. , 0. , 0. , 0. , -0.2 ]])" ] } ], "prompt_number": 5 }, { "cell_type": "markdown", "metadata": {}, "source": [ "* Observe bandwidth growth.\n", "* Asymptotic cost of operating on banded matrices? (Mat-vec? Factorization?)" ] } ], "metadata": {} } ] }