I am not clear about the solution given for Q5 or maybe I have not got the question right.
Q5 Write a function to iteratively sum up the value of x^n/n factorial from n=1 to a chosen value of N’ such that F(x,N’)- F(x,N’-1)<e for a given real number x and positive small number e.
What I understand is that you are given x and e (say x=2 and e = 0.01) then find a N’ such that F(x,N’) - F(x,N’-1) is < 0.01 and then find the sum of x^N’/N’factorial. Where F(x,N’) is the series sum 1+ sigma of x^i/i factorial with i ranging from 1 to N’.
as per me the correct code should be
where sum_socratic is the function
for i in range(1,N+1):
and socratic is defined as
However the solution given does something else.
Could you please point out where I am going wrong. Why are we not calculating the difference between F(x,N) and F(x,N-1) and then seeing if it is less than epsilon. Also the while loop condition is put as var>=epsilon whereas in the question it is <epsilon. So if there a mathematical shortcut that has been used to arrive at the same result and the code has been written for that shortcut?
BTW the function given in the solution can be further shortened as