1
$\begingroup$

I am wondering what the reason for the following is

We know that ,

exponential has a taylor representation : $$exp(x)=1+x+\frac{x^{2}}{2!}+\frac{x^{3}}{3!}+...$$

Using the first n terms , in R , I compute

$\exp(-10)$ and get one answer.

However, if I compute $\frac{1}{\exp(10)}$, I get a slightly different answer.

For example, when I use the first 30 terms of the Taylor Series,

I get

$\exp(-10)=0.0009703416$

but $\frac{1}{\exp(10)}=4.539993\times10^{-5}$

Once I get to a large enough number of iterations, both converge to the correct value.

So why do we get differing answers when I use the same method, only replacing by a division of 1 over?

Thanks!

$\endgroup$
3
$\begingroup$

For $\exp(-10)$, more terms have to be computed since the 30-th term $\dfrac{(-10)^{30}}{30!}\approx 0.00377$ is several times bigger than the partial sum so far, 0.0009703416.

For $\exp(10)$, all terms are positive. The 30-th term $\dfrac{(10)^{30}}{30!}\approx 0.00377$ is already substantially negligible to the partial sum so far, 22026.464.

Here is the output of the program of my Python program that computes $\exp(-10)$ by that Taylor series. The first column tells the ordinals of the terms. The second columns show the values of that terms. The third terms is the partial sums so far.

0                     1.0                     1.0
1                   -10.0                    -9.0
2                    50.0                    41.0
3     -166.66666666666666     -125.66666666666666
4      416.66666666666663                   291.0
5     -833.33333333333326     -542.33333333333326
6      1388.8888888888887      846.55555555555543
7     -1984.1269841269839     -1137.5714285714284
8      2480.1587301587297      1342.5873015873012
9     -2755.7319223985887     -1413.1446208112875
10      2755.7319223985887      1342.5873015873012
11     -2505.2108385441716     -1162.6235369568703
12      2087.6756987868098      925.05216182993945
13     -1605.9043836821616      -680.8522218522221
14      1147.0745597729726      466.22233792075053
15     -764.71637318198179     -298.49403526123126
16      477.94773323873864      179.45369797750737
17     -281.14572543455211     -101.69202745704473
18      156.19206968586229      54.500042228817563
19     -82.206352466243317     -27.706310237425754
20      41.103176233121658      13.396865995695904
21     -19.572941063391266     -6.1760750676953613
22      8.8967913924505755      2.7207163247552142
23     -3.8681701706306848     -1.1474538458754706
24      1.6117375710961186     0.46428372522064798
25    -0.64469502843844739    -0.18041130321779941
26     0.24795962632247978    0.067548323104680369
27    -0.09183689863795548   -0.024288575533275111
28    0.032798892370698378     0.00851031683742327
29   -0.011309962886447721  -0.0027996460490244501
30   0.0037699876288159102  0.00097034157979145996
31  -0.0012161250415535199 -0.00024578346176205997
32  0.00038003907548547002  0.00013425561372341999
33    -0.00011516335620772       1.90922575157e-05
34  3.3871575355210003e-05  5.2963832870910003e-05
35 -9.6775929586300006e-06  4.3286239912280003e-05
36  2.6882202662899999e-06  4.5974460178560002e-05
37 -7.2654601791999997e-07  4.5247914160649999e-05
38  1.9119632050000001e-07  4.5439110481150002e-05
39 -4.9024697569999999e-08      4.539008578359e-05
40         1.225617439e-08  4.5402341957980002e-05
41 -2.9893108300000001e-09  4.5399352647149997e-05
42  7.1174066999999995e-10  4.5400064387830001e-05
43 -1.6552109000000001e-10  4.5399898866740002e-05
44            3.761843e-11      4.539993648517e-05
45 -8.3596500000000006e-12  4.5399928125519999e-05
46             1.81732e-12      4.539992994283e-05
47 -3.8665999999999999e-13  4.5399929556169997e-05
48  8.0549999999999995e-14  4.5399929636719997e-05
49 -1.6440000000000001e-14  4.5399929620280003e-05
50  3.2899999999999998e-15  4.5399929623570001e-05
51 -6.4000000000000005e-16  4.5399929622930003e-05
52                 1.2e-16  4.5399929623049997e-05
53 -2.0000000000000001e-17      4.539992962303e-05
54                     0.0      4.539992962303e-05
55                    -0.0      4.539992962303e-05
4.539992962303116e-05

Although the partial sums becomes stable after 55-th term, not all digits of 4.539992962303e-05 is correct, because of the precision of the terms such as the 8-th term. The actual value of $\exp(-10)$ should be something like 4.5399929762485e-05

In the end, it is faster and easier to compute $\exp(-x)$ to a specified precision using $\dfrac1{\exp(x)}$ instead of directly for $x>0$, especially when $x$ is large.

$\endgroup$
  • $\begingroup$ Sorry I missed it above but not in my program. (My program includes the one, I add it at the end , so it isn't related to the issue, thank you though, for example the answer I included for 1/exp(10) is actually the correct value). $\endgroup$ – Quality Jan 12 at 4:48
  • $\begingroup$ I see. Updated. $\endgroup$ – Apass.Jack Jan 12 at 6:02

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.