Asked by Gina

Write an application that calculates the value of e^x by using the following formula:e^x=1+(x/1!)+(x^2/2!)+(x^3/3!)...
Allow the user to enter the number of terms to calculate

Answers

Answered by MathMate
Are you writing it in C++, java or VB.net?

I suppose you have just finished control statements, and should be capable of writing the required application.

Have you started coding. Post your code if you have difficulties.
Answered by Gina
I don't understand the formula :/
Answered by Gina
I don't understand the formula :/ im writing in java
Answered by MathMate
The formula for
e<sup>x</sup> can be approximated by the infinite series:
e<sup>x</sup>
= 1 + x + x²/2! + x³/3! + ... (ad infinitum)
where 2! = factorial 2 = 1*2, and
3! = factorial 3 = 1*2*3, etc.

So for a given value of x, say 0.2,
to approximate e<sup>0.2</sup>, we calculate
e<sup>0.2</sup>
=1+0.2+0.2²/(1*2)+0.2³/(1*2*3)+0.2<sup>4</sup>/(1*2*3*4)+...
=1+0.20000+0.020000+0.001333+0.000067+0.000003+....
=1.221403

The actual value from a calculator would be 1.221402758...

Notice that each term can be calculated from the preceding one by multiplying by x and dividing by a successively higher integer, 1,2,3...
You could try the following pseudocode:

term=1 // first term
sum=term // accumulator
counter=1 // term counter
eps=0.000001 // accuracy required
input x // value of x for which e^x required
while(abs(term)>eps)
term <- term * x/counter
counter ++
sum <- sum + term
loop

Post your code if you have questions.

Related Questions