Why using power serie the result was so different ? I imagine it happened due to the truncation, I used 20 terms, are more terms needed ?
EDITED: The code is below
import numpy as np
import cmath
from matplotlib import pyplot as plt
def exponentialFunction(x, interval):
y = [0 for i in range(interval)]
for n in range(0,interval):
y[n] = (1 + x[n]/(n+1))**n
return y
def truncatedExponentialFunction(x, interval):
y = [0 for i in range(interval)]
for n in range(0,interval):
y[n] = 1 + x[n] + (x[n]**2)/np.math.factorial(2) + \
(x[n]**3)/np.math.factorial(3) + \
(x[n]**4)/np.math.factorial(4) + (x[n]**5)/np.math.factorial(5) + \
(x[n]**6)/np.math.factorial(6) + (x[n]**7)/np.math.factorial(7) + \
(x[n]**8)/np.math.factorial(8) + (x[n]**9)/np.math.factorial(9) + \
(x[n]**10)/np.math.factorial(10) + (x[n]**11)/np.math.factorial(11) + \
(x[n]**12)/np.math.factorial(12) + (x[n]**13)/np.math.factorial(13) + \
(x[n]**14)/np.math.factorial(14) + (x[n]**15)/np.math.factorial(15) + \
(x[n]**16)/np.math.factorial(16) + (x[n]**17)/np.math.factorial(17) + \
(x[n]**18)/np.math.factorial(18) + (x[n]**19)/np.math.factorial(19) + \
(x[n]**20)/np.math.factorial(20)
return y
interval = 10000
k = np.linspace(0, 8*np.pi, interval)
z = complex(0,1)
x = z*k
y = truncatedExponentialFunction(x,interval)
w = exponentialFunction(x,interval)
fig, ax = plt.subplots(2, 2)
ax[0, 0].set_title("Exp. Function - real")
ax[0, 0].plot(k, np.real(w))
ax[0, 1].set_title("Exp. Function - imag")
ax[0, 1].plot(k, np.imag(w))
ax[1, 0].set_title(" Power Serie - real")
ax[1, 0].plot(k, np.real(y))
ax[1, 1].set_title(" Power Serie - imag")
ax[1, 1].plot(k, np.imag(y))
fig.tight_layout(pad=1.0)
plt.show()
