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.
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
4 answers
I don't understand the formula :/
I don't understand the formula :/ im writing in java
The formula for
ex can be approximated by the infinite series:
ex
= 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 e0.2, we calculate
e0.2
=1+0.2+0.2²/(1*2)+0.2³/(1*2*3)+0.24/(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.
ex can be approximated by the infinite series:
ex
= 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 e0.2, we calculate
e0.2
=1+0.2+0.2²/(1*2)+0.2³/(1*2*3)+0.24/(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.