{"metadata": {"name": "", "signature": "sha256:69ee781e77f94954a0ec5c0fcadd8bb26f9404c604062e65f62452a8419fc17b"}, "nbformat": 3, "worksheets": [{"metadata": {}, "cells": [{"cell_type": "markdown", "source": ["# Orthogonalizing three vectors"], "metadata": {}}, {"language": "python", "metadata": {}, "prompt_number": 1, "cell_type": "code", "outputs": [], "input": ["import numpy as np\n", "import numpy.linalg as la"], "collapsed": false}, {"language": "python", "metadata": {}, "prompt_number": 3, "cell_type": "code", "outputs": [], "input": ["np.random.seed(13)\n", "xorig = np.random.randn(200)\n", "yorig = np.random.randn(200)\n", "zorig = np.random.randn(200)"], "collapsed": false}, {"cell_type": "markdown", "source": ["Orthonormalize $x$ and $y$ as we know:"], "metadata": {}}, {"language": "python", "metadata": {}, "prompt_number": 4, "cell_type": "code", "outputs": [], "input": ["x = xorig/la.norm(xorig)"], "collapsed": false}, {"language": "python", "metadata": {}, "prompt_number": 6, "cell_type": "code", "outputs": [], "input": ["y = yorig\n", "y = y - x.dot(y)*x\n", "y = y / la.norm(y)"], "collapsed": false}, {"cell_type": "markdown", "source": ["Check:"], "metadata": {}}, {"language": "python", "metadata": {}, "prompt_number": 7, "cell_type": "code", "outputs": [{"text": ["1.0\n", "1.0\n", "-4.07660016855e-17\n"], "stream": "stdout", "output_type": "stream"}], "input": ["print(la.norm(x))\n", "print(la.norm(y))\n", "print(x.dot(y))"], "collapsed": false}, {"cell_type": "markdown", "source": ["Now what to with $z$?"], "metadata": {}}, {"language": "python", "metadata": {}, "prompt_number": 8, "cell_type": "code", "outputs": [], "input": ["z = zorig\n", "z = z - np.dot(z, x)*x - np.dot(z,y)*y\n", "z = z / la.norm(z)"], "collapsed": false}, {"cell_type": "markdown", "source": ["Check:"], "metadata": {}}, {"language": "python", "metadata": {}, "prompt_number": 9, "cell_type": "code", "outputs": [{"text": ["1.0\n", "-1.38777878078e-17\n", "-3.68628738645e-17\n"], "stream": "stdout", "output_type": "stream"}], "input": ["print(la.norm(z))\n", "print(x.dot(z))\n", "print(y.dot(z))"], "collapsed": false}]}], "nbformat_minor": 0}