I have the following summation function:
import numpy as np
from sympy import var, Sum, pi, factorial, limit
import matplotlib.pyplot as plt
import math
import scipy.misc
def n_series(x, k):
n = np.arange(k)
X, N = np.meshgrid(x, n)
val =(((-1)**N)*X**(2*N + 1)) / factorial(2*N + 1)
return np.sum(val, axis=0)
x0 = np.pi/2
x1= 2 * np.pi
x = np.linspace(x0, x1, 100)
for k in [0, 1, 5]:
plt.plot(x, n_series(x, k), label=str(k))
plt.show()
and I would like to plot it for the following values: [0, 1, 5]
but unfortunately I get this error message:

and this:
any ideas on the this problem would be appreciated.
>Solution :
You are using sympy’s factorial on numerical data types: if possible, avoind mixing symbolic functions with numerical data.
Replace sympy’s factorial with the one from scipy:
from scipy.special import factorial
After that you are going to get the plot:

