trapezoid_rule.ipynb
117 lines
| 22.7 KiB
| text/plain
|
TextLexer
|
r4776 | { | |
|
r5279 | "metadata": { | |
"name": "trapezoid_rule" | |||
}, | |||
"nbformat": 2, | |||
|
r4776 | "worksheets": [ | |
{ | |||
"cells": [ | |||
{ | |||
|
r5279 | "cell_type": "markdown", | |
"source": [ | |||
"Basic numerical integration: the trapezoid rule", | |||
"===============================================", | |||
"", | |||
"A simple illustration of the trapezoid rule for definite integration:", | |||
"", | |||
"$$", | |||
"\\int_{a}^{b} f(x)\\, dx \\approx \\frac{1}{2} \\sum_{k=1}^{N} \\left( x_{k} - x_{k-1} \\right) \\left( f(x_{k}) + f(x_{k-1}) \\right).", | |||
"$$", | |||
"<br>", | |||
"First, we define a simple function and sample it between 0 and 10 at 200 points" | |||
] | |||
|
r4776 | }, | |
{ | |||
"cell_type": "code", | |||
|
r5279 | "collapsed": true, | |
"input": [ | |||
"def f(x):", | |||
" return (x-3)*(x-5)*(x-7)+85", | |||
"", | |||
"x = linspace(0, 10, 200)", | |||
"y = f(x)" | |||
], | |||
|
r4776 | "language": "python", | |
"outputs": [], | |||
|
r5279 | "prompt_number": 1 | |
|
r4776 | }, | |
{ | |||
|
r5279 | "cell_type": "markdown", | |
"source": [ | |||
"Choose a region to integrate over and take only a few points in that region" | |||
] | |||
|
r4776 | }, | |
{ | |||
"cell_type": "code", | |||
|
r5279 | "collapsed": true, | |
"input": [ | |||
"a, b = 1, 9", | |||
"xint = x[logical_and(x>=a, x<=b)][::30]", | |||
"yint = y[logical_and(x>=a, x<=b)][::30]" | |||
], | |||
|
r4776 | "language": "python", | |
"outputs": [], | |||
|
r5279 | "prompt_number": 2 | |
|
r4776 | }, | |
{ | |||
|
r5279 | "cell_type": "markdown", | |
"source": [ | |||
"Plot both the function and the area below it in the trapezoid approximation" | |||
] | |||
|
r4776 | }, | |
{ | |||
"cell_type": "code", | |||
|
r5279 | "collapsed": false, | |
"input": [ | |||
"plot(x, y, lw=2)", | |||
"axis([0, 10, 0, 140])", | |||
"fill_between(xint, 0, yint, facecolor='gray', alpha=0.4)", | |||
"text(0.5 * (a + b), 30,r\"$\\int_a^b f(x)dx$\", horizontalalignment='center', fontsize=20);" | |||
], | |||
|
r4776 | "language": "python", | |
"outputs": [ | |||
{ | |||
"output_type": "display_data", | |||
"png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD3CAYAAADmBxSSAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAIABJREFUeJzt3XlcVXX+x/HXZUfZZVEBV9TY3Usnk1Iy0Db3vbFlmspp\nMmd+beOgVlq2mDXjtDqTMjMuY7mBpGZYmYpiiLihbHIRZRNkX+/vjyOb4sL1wrnA5/l43Mc9nMs5\n5+N91Nuv3/M9369Gp9PpEEII0a6YqF2AEEIIw5NwF0KIdkjCXQgh2iEJdyGEaIck3IUQoh2ScBdC\niHbopuH+5JNP4ubmhr+//3WfffDBB5iYmJCXl1e3b/ny5fj4+ODv78+uXbsMX60QQojbctNwnzdv\nHlFRUdftT09PZ/fu3fTs2bNuX2xsLN988w3Hjx8nKiqKZ599loqKCsNXLIQQ4pZuGu6jRo3C0dHx\nuv0vv/wyK1asaLQvIiKC6dOnY2pqiru7O76+vsTExBi2WiGEELfFrLkHbN26FQ8PDwICAhrtz8jI\n4IEHHqj72cPDA61We93xGo1GjzKFEEI0Z0KBZt1QLSkpYdmyZSxZskSvizU8Rl46wsLCVK/BWF7y\nXch30Va+i9GjdYCOFSta97rN1ayWe1JSEqmpqQQGBgKg1WoZMmQIhw4dwsPDg/T09Lrf1Wq1eHp6\nNrsgIYQwVocOwb59YG8Pzz6rdjU316yWu7+/P5cuXSIlJYWUlBQ8PDw4evQobm5uhIaGsmHDBqqq\nqtBqtSQkJDB8+PCWqlsIIVrdu+8q7889B3Z26tZyKzcN9xkzZjBy5EgSExPx9PTkn//8Z6PPG/af\nDxkyhMcff5yAgAAeeughPvvsM8zNzVum6nYiKChI7RKMhnwX9eS7qGdM38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EQQoh2SsJdCCHaIQl3IYRohyTchRCiHZJwF0KIdkjC\nXQgh2qH/B7d8dxd+Imh6AAAAAElFTkSuQmCC\n" | |||
} | |||
], | |||
|
r5279 | "prompt_number": 3 | |
|
r4776 | }, | |
{ | |||
|
r5279 | "cell_type": "markdown", | |
"source": [ | |||
"Compute the integral both at high accuracy and with the trapezoid approximation" | |||
] | |||
|
r4776 | }, | |
{ | |||
"cell_type": "code", | |||
|
r5279 | "collapsed": false, | |
"input": [ | |||
"from scipy.integrate import quad, trapz", | |||
"integral, error = quad(f, 1, 9)", | |||
"print \"The integral is:\", integral, \"+/-\", error", | |||
"print \"The trapezoid approximation with\", len(xint), \"points is:\", trapz(yint, xint)" | |||
], | |||
|
r4776 | "language": "python", | |
"outputs": [ | |||
{ | |||
"output_type": "stream", | |||
|
r5279 | "stream": "stdout", | |
"text": [ | |||
"The integral is: 680.0 +/- 7.54951656745e-12", | |||
"The trapezoid approximation with 6 points is: 621.286411141" | |||
] | |||
|
r4776 | } | |
], | |||
|
r5279 | "prompt_number": 4 | |
|
r4776 | }, | |
{ | |||
"cell_type": "code", | |||
"collapsed": true, | |||
|
r5279 | "input": [], | |
|
r4776 | "language": "python", | |
"outputs": [] | |||
} | |||
] | |||
} | |||
|
r5279 | ] | |
} |