(* Compute e(x) using Taylor series *) (* To execute, type << Exp.math at the Mathematica prompt *) (* Start with z=1, LIM=5. Seems to work OK. Try z=20 now. *) (* You will have to increase LIM to 40 to get reasonable accuracy *) (* Now try z = -20 The result is nowhere near the correct value! *) (* Moreover, increasing the number of iterations to, say, LIM=41 *) (* leads to a very different and again completely wrong answer *) (* This is an example of a "bad algorithm". A "good algorithm" will *) (* compute e^-20 as e^-20 = 1/e^20 *) z= 1.0 LIM = 5 Print["Taylor series result for e(z):"] Print [NSum[z^k/k!, {k, 0, LIM}] ] Print["Exact result:"] Print [ Exp[z] ] Clear[z] Clear[LIM]