Lesson goal: The Derivative

Previous: Computing Pi using factorials | Home | Next: Doing integrals numerically

In Calculus, the derivative of a function $f(x)$ is given by $f'(x)$ which is $$f'(x)=\frac{f(x+h)-f(x)}{h},$$ in the limit as $h\rightarrow 0$. Let's test this defintion here. Think of a function $f(x)$ and it's derivative, $g(x)$. As example, if $f(x)=sin(x)$ then $g(x)=cos(x)$. Let's compute $f'(x)$ according to the definition above, letting $h$ get smaller and smaller, and compare $f'(x)$ at some $x$ with the analytical derivative, $g(x)$ at the same $x$. Let's see what we get.

Now you try. Fix the return statements in both the f(x) and g(x) functions. Then fix the maximum value of i you wish to run through in the for-loop.

Type your code here:


See your results here: