I'm attempting to calculate e^x using recursion, e^x = e^(x/2)*e^(x/2), and the third order Maclaurin expansion for e^x and the script keeps returning 1. I'm not looking for a higher accuracy solution, just simply to understand where the script goes wrong : )
My thought is that with enough iterations it should end up with (1+x/N+(x/N)^2/2)^N when the function value goes below the limit.
def exp(x):
if abs(x)<0.0001:
return 1+x+x**2/2
else:
y=exp(x/2)
return y*y
from __future__ import division
at the top of your script – Fusco