I've been wrestling with this issue for a week and I just need some guidance on the math part of it. If I could just understand the math behind it I could piece together the functions to make it work. The assignment is;
Design and develop a C++ program for Calculating e(n) when delta <= 0.000001
- e(n-1) = 1 + 1/1! + 1/2! + 1/3! + 1/4! + … + 1/(n-1)!
- e(n) = 1 + 1/1! + 1/2! + 1/3! + 1/4! + … + 1/(n)!
delta = e(n) – e(n-1)
You do not have any input to the program. Your output should be something like this:
- N = 2 e(1) = 2 e(2) = 2.5 delta = 0.5
- N = 3 e(2) = 2.5 e(3) = 2.565 delta = 0.065 ...
You must use recursive function calls.
My first issue is the math and the variables that would contain them.
- the delta, e(n), and e(n-1) variable must doubles
- if e(n) = 1 + 1 / 1! = 2 then e(n-1) must equal 1, which means delta = 1 (that's my thinking anyway) I'm just not sure of the math behind the .5 delta the first time and the 0.065 in the second iteration.
Can someone point me in the right direction on this problem?
Thank you,
T
your e(n) series is the Tylor series for $e^x$ evaluated at $x=1$, so it will converge to $e$. As you keep adding terms, the error between your current sum and $e$ will decrease (since this series converges), and so will the differences between a term and the previous one. $e=2.718281828...$
'the delta, e(n), and e(n-1) variable must doubles' ok
'if e(n) = 1 + 1 / 1! = 2 then e(n-1) must equal 1, which means delta = 1' ok
'I'm just not sure of the math behind the .5 delta the first time and the 0.065 in the second iteration.' In each iteration the errors will keep decreasing, since your program will converge to $e$ as I said above, so don't be troubled by it.
It seems you get it all right, just go ahead and code!