Created
November 21, 2014 10:43
-
-
Save olivierverdier/157eac7b81960e1cf7b3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"worksheets": [ | |
{ | |
"cells": [ | |
{ | |
"metadata": {}, | |
"cell_type": "heading", | |
"source": "Exercise for the course [Python for MATLAB users](http://sese.nu/python-for-matlab-users/), by Olivier Verdier", | |
"level": 2 | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "code", | |
"input": "%pylab\n%matplotlib inline\nfrom __future__ import division", | |
"outputs": [], | |
"language": "python", | |
"trusted": true, | |
"collapsed": false | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "A numerical derivative of a function $f$ is a formula of the type\n\\\\[\nf'(x_0) \\simeq \\frac{f(x_0+h/2) - f(x_0-h/2)}{h}\n\\\\]" | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "markdown", | |
"source": "Implement a function `derivator` which returns the derivative *function*." | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "code", | |
"input": "def derivator(f, h):\n pass", | |
"outputs": [], | |
"language": "python", | |
"trusted": true, | |
"collapsed": false | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "code", | |
"input": "msin_ = derivator(cos, 1e-10)", | |
"outputs": [], | |
"language": "python", | |
"trusted": true, | |
"collapsed": false | |
}, | |
{ | |
"metadata": {}, | |
"cell_type": "code", | |
"input": "assert(allclose(msin_(0), 0))\nassert(allclose(msin_(pi), 0))\nassert(allclose(msin_(pi/2), -1.))", | |
"outputs": [], | |
"language": "python", | |
"trusted": true, | |
"collapsed": false | |
} | |
], | |
"metadata": {} | |
} | |
], | |
"metadata": { | |
"name": "", | |
"signature": "sha256:c1fbf7738453643a5e54a78005fd9c9e4982363fe087fccb328279384f8352bf" | |
}, | |
"nbformat": 3 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment