{ "cells": [ { "cell_type": "markdown", "metadata": { "slideshow": { "slide_type": "slide" } }, "source": [ "## Simple iteration to solve a linear system\n", "\n", "We want to solve the equation $Ax = b$. Recall that every root-finding problem has equivalent, associated fixed-point iterations. If $x$ is a solution of $Ax = b$ then $x$ satisfies\n", "\n", "$$x = (I - A)x + b.$$\n", "\n", "and we want to find a fixed-point of \n", "\n", "$$g(x) = (I - A)x + b.$$" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "slideshow": { "slide_type": "slide" } }, "outputs": [ { "data": { "text/plain": [ "array([[ -5.30764743e-09],\n", " [ -2.58408872e-09],\n", " [ -3.60924202e-09],\n", " [ -3.46897711e-09]])" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "import numpy as np\n", "A = np.array([[1.1, .1, .3, .4], \n", " [.2, .9, -.1, .33], \n", " [-.3, .4, 1., .8], \n", " [.1, .2, .3, 1]])\n", "b = np.array([[1], \n", " [1], \n", " [1], \n", " [1]])\n", "T = np.eye(4) - A\n", "x = np.array([[0],\n", " [0],\n", " [0],\n", " [0]])\n", "for i in range(40):\n", " x = np.dot(T,x) + b\n", "np.dot(A,x) - b" ] } ], "metadata": { "celltoolbar": "Slideshow", "kernelspec": { "display_name": "Python 2", "language": "python", "name": "python2" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 2 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython2", "version": "2.7.14" } }, "nbformat": 4, "nbformat_minor": 1 }