Home > Blockchain >  Plotting the summation over different values
Plotting the summation over different values

Time:04-19

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 b_func(x, k):
    n = np.arange(k)
    X, N = np.meshgrid(x, n)
    val =((X**(2*N)) / factorial(2*N)
    return np.sum(val)

x0 = np.pi/2
x1= 2 * np.pi

x = np.linspace(x0, x1, 100)
  
for k in [0]:
    plt.plot(x, b_func(x, k))

plt.show()

and I would like to plot it for the following values: [0] but unfortunately I get this error message: enter image description here

and this:

enter image description here

any ideas on the this problem would be appreciated.

CodePudding user response:

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:

enter image description here

  • Related