Arnoldjavs3 said:
I uploaded the file here if you're interested:
http://www.filedropper.com/spie19991
Not sure why your browser is flagging that site... Loaded for me fine. Proceed at own risk though, lol.
Also, back to your original suggestion. I have a question about computing ##e^x## where ##0<x<1##. How do you put this into the series? As in, how do I account for the factorial part where ##x## is not a whole integer(here is my lack of math kicking in). I read something called the Gamma function. Would i implement that here to find the factorial?
For ##0 < x < 1## you can use the series
$$ e^x = \sum_{n=0}^{\infty} \frac{x^n}{n!} = 1 + \frac{x}{1} + \frac{x^2}{2 \cdot 1} + \frac{x^3}{3 \cdot 2 \cdot 1} + \cdots $$
Only positive integer values of ##n!## are involved, so there is no need for anything fancy. The best way of computing your approximation is to do it recursively, in something like the following.
(1) ##S = 1##, ##n = 1##
(2) ##t = x/n##, ##S = S + t##, ##n = n+1##
(3) ##t = t*x/n##, ##S=S + t##, ##n = n+1##
(4) while ##t \geq \epsilon## repeat step (3), else stop.
Here, ##\epsilon > 0## is some stopping criterion, so that we stop summing when the newest term is ##< \epsilon##. The final value of ##S## is our approximation to ##e^x##, and should have an error not much larger than ##\epsilon##.
On the other hand, if you have some reasonable pre-specified accuracy you want to achieve, there are numerous more easily-implemented methods with known error bounds available. For example, on page 71 of "Handbook of Mathematical Functions", by Ambramowitz and Stegun (Dover Publications) there are several apprximations of various degrees of accuracy. The subsection 4.2.45 gives the polynomial formula
$$e^{-x} = 1 + a_1 x + a_2 x^2 + a_3 x^3+a^4 x^4 + a_5 x^5 + a_6 x^6 + a_7 x^7 + \epsilon(x),$$
where numerical values are given for ##a_1, a_2, \ldots, a_7## and the error is known to satisfy
$$|\epsilon(x)| \leq 2 \times 10^{-10}$$
for ##0 \leq x \leq \ln 2 \approx 0.693##.
Note that the ##a_i## are not just ##(-1)^i/i!## as would appear in the series; they are fancier values, based on extensive numerical analysis and testing. (The values of the ##a_i## are not greatly different from ##(-1)^i /! ##, but deviate from these after about the 5th decimal place.)
If you are satisfied with a worst-case error of about ##10^{-10}## you could use that polynomial. Probably it would be best to limit ##x## to values ##\leq 0.5## in the polynomial, which you could easily do by (1) pre-computing and storing an accurate value for ##e^{0.5}##, then (2) using ##e^x = e^{0.5} \, e^{x-0.5} ## for ##.5 < x < 1##. Compute the approximate value of ##e^{x-.5}## using the polynomial approximation for ##e^{-(x-.5)} = e^{.5 - x}## and then computing ##e^z## as ##1/e^{-z}##. Of course, for ##0 < x \leq 0.5## you compute ##e^x = 1/e^{-x}## directly, using the polynomial to evaluate ##e^{-x}##.
Newer sources contain a wide variety of other schemes; many people seem to favor the use of Pade approximants, which are essentially rational functions rather than simple polynomials.