{"worksheets": [{"cells": [{"cell_type": "markdown", "metadata": {}, "source": ["# Computing the weights in Simpson's rule"]}, {"metadata": {}, "collapsed": false, "input": ["import numpy as np\n", "import numpy.linalg as la"], "cell_type": "code", "outputs": [], "language": "python", "prompt_number": 3}, {"cell_type": "markdown", "metadata": {}, "source": ["We found the integrals:\n", "\n", "$$\n", "\\begin{align*}\n", "\\int_0^1 1 dx &= 1\\\\\n", "\\int_0^1 x dx &= \\frac 12 \\\\\n", "\\int_0^1 x^2 dx &= \\frac 13 \\\\\n", "\\end{align*}\n", "$$\n"]}, {"metadata": {}, "collapsed": false, "input": ["integrals = np.array([1, 1/2, 1/3])"], "cell_type": "code", "outputs": [], "language": "python", "prompt_number": 4}, {"metadata": {}, "collapsed": false, "input": ["nodes = np.linspace(0, 1, 3)\n", "nodes"], "cell_type": "code", "outputs": [{"metadata": {}, "text": ["array([ 0. , 0.5, 1. ])"], "output_type": "pyout", "prompt_number": 6}], "language": "python", "prompt_number": 6}, {"metadata": {}, "collapsed": false, "input": ["V = np.array([\n", "1+0*nodes,\n", "nodes,\n", "nodes**2\n", "]).T\n", "V"], "cell_type": "code", "outputs": [{"metadata": {}, "text": ["array([[ 1. , 0. , 0. ],\n", " [ 1. , 0.5 , 0.25],\n", " [ 1. , 1. , 1. ]])"], "output_type": "pyout", "prompt_number": 8}], "language": "python", "prompt_number": 8}, {"cell_type": "markdown", "metadata": {}, "source": ["Now compute the weights:"]}, {"metadata": {}, "collapsed": false, "input": ["la.inv(V).T.dot(integrals)"], "cell_type": "code", "outputs": [{"metadata": {}, "text": ["array([ 0.16666667, 0.66666667, 0.16666667])"], "output_type": "pyout", "prompt_number": 11}], "language": "python", "prompt_number": 11}, {"metadata": {}, "collapsed": false, "input": [], "cell_type": "code", "outputs": [], "language": "python"}], "metadata": {}}], "nbformat_minor": 0, "metadata": {"signature": "sha256:0708d723e30da602780d3e593257a553c939166e8b9888cb5ae7f395f5fed674", "name": ""}, "nbformat": 3}