Assignment
The exponential function can be calculated by a series expansion:
Write a function that takes a scalar input x and provides scalar output of the exponential function.
A few notes/hints:
- Use the factorial function that you wrote (you can revise it, of course). Thus, in your script file you'll have to have at least two functions defined.
- Also, since you cannot calculate an infinite series, you have to decide when the sum has converged enough. That is accomplished by testing the result against some preset tolerance. Set that tolerance using a keyword parameter as input.
- Include docstrings in your functions.
- You can write this without using
numpy
arrays. You might want to try awhile
loop.
Here's an example of the sort of input/output I'd like to see.
I'm assuming you have already imported your exponential function
and have named it exponential
:
>>> print exponential(3.4, tol=1e-8) 29.9641000474
Solution
See the following web page.