{"nbformat": 3, "nbformat_minor": 0, "metadata": {"signature": "sha256:28cd14c236e1d04a0bd5c1ff646ba42ef8c77a5886ecdbb84389890cf060bfc6", "name": ""}, "worksheets": [{"cells": [{"source": ["# Computing the Nullspace"], "cell_type": "markdown", "metadata": {}}, {"metadata": {}, "prompt_number": 16, "language": "python", "input": ["import numpy as np\n", "import numpy.linalg as la"], "cell_type": "code", "outputs": [], "collapsed": false}, {"metadata": {}, "prompt_number": 17, "language": "python", "input": ["n = 5\n", "np.random.seed(25)\n", "A = np.random.randn(n, n)\n", "\n", "# Decrease the rank\n", "A[4] = A[0] + 5 * A[2]\n", "A[1] = 3 * A[0] -2 * A[3]"], "cell_type": "code", "outputs": [], "collapsed": false}, {"metadata": {}, "prompt_number": 18, "language": "python", "input": ["from m_echelon import m_echelon"], "cell_type": "code", "outputs": [], "collapsed": false}, {"metadata": {}, "prompt_number": 29, "language": "python", "input": ["M, U = m_echelon(A.T)"], "cell_type": "code", "outputs": [], "collapsed": false}, {"metadata": {}, "prompt_number": 30, "language": "python", "input": ["la.norm(\n", " M.dot(A.T) - U)"], "cell_type": "code", "outputs": [{"output_type": "pyout", "metadata": {}, "text": ["1.2599818366099757e-15"], "prompt_number": 30}], "collapsed": false}, {"metadata": {}, "prompt_number": 31, "language": "python", "input": ["U.round(3)"], "cell_type": "code", "outputs": [{"output_type": "pyout", "metadata": {}, "text": ["array([[ 1.027, 0.676, -0.232, 1.202, -0.135],\n", " [ 0. , -3.498, -1.468, 1.749, -7.342],\n", " [ 0. , 0. , -2.14 , 0. , -10.699],\n", " [ 0. , 0. , 0. , 0. , -0. ],\n", " [ 0. , 0. , 0. , 0. , -0. ]])"], "prompt_number": 31}], "collapsed": false}, {"source": ["Now define `NUT` as vectors spanning the nullspace of $N(U^T)$."], "cell_type": "markdown", "metadata": {}}, {"metadata": {}, "prompt_number": 32, "language": "python", "input": ["NUT = np.eye(n)[:, 3:]\n", "NUT"], "cell_type": "code", "outputs": [{"output_type": "pyout", "metadata": {}, "text": ["array([[ 0., 0.],\n", " [ 0., 0.],\n", " [ 0., 0.],\n", " [ 1., 0.],\n", " [ 0., 1.]])"], "prompt_number": 32}], "collapsed": false}, {"source": ["Check that it's actually a nullspace:"], "cell_type": "markdown", "metadata": {}}, {"metadata": {}, "prompt_number": 33, "language": "python", "input": ["U.T.dot(NUT)"], "cell_type": "code", "outputs": [{"output_type": "pyout", "metadata": {}, "text": ["array([[ 0.000e+00, 0.000e+00],\n", " [ 0.000e+00, 0.000e+00],\n", " [ 0.000e+00, 0.000e+00],\n", " [ 3.644e-16, 6.163e-33],\n", " [ -1.776e-15, -2.174e-16]])"], "prompt_number": 33}], "collapsed": false}, {"source": ["Now define `NA` as some vectors spanning $N(A)$:"], "cell_type": "markdown", "metadata": {}}, {"metadata": {}, "prompt_number": 34, "language": "python", "input": ["NA = M.T.dot(NUT)"], "cell_type": "code", "outputs": [], "collapsed": false}, {"source": ["And check:"], "cell_type": "markdown", "metadata": {}}, {"metadata": {}, "prompt_number": 35, "language": "python", "input": ["A.dot(NA)"], "cell_type": "code", "outputs": [{"output_type": "pyout", "metadata": {}, "text": ["array([[ 1.110e-16, -1.110e-16],\n", " [ 4.441e-16, -4.441e-16],\n", " [ -2.220e-16, -5.551e-17],\n", " [ 1.110e-16, 1.110e-16],\n", " [ -8.882e-16, -6.661e-16]])"], "prompt_number": 35}], "collapsed": false}, {"metadata": {}, "language": "python", "input": [], "cell_type": "code", "outputs": [], "collapsed": false}], "metadata": {}}]}