I am new at coding and I am trying to plot the fallowing function.
H_n(x)=Sum((-1.)^(k)(N!))/((k)!(N-2.k)!)((2.*x)^(N-2.*k)) where k=0->(N/2) and N is an integer that is defined by the user.
I get the fallowing error: TypeError: unsupported operand type(s) for ** or pow(): 'float' and 'function'
Here is my code I've done thus far.
from matplotlib.pyplot import plot, show
import numpy as np
import math
N = input('define N: ')
def factorial(N):
if N <= 1:
return 1
else:
return N * factorial(N-1)
def k(N):
s = 0
for i in np.arange(0,N/2):
s += 1
return k
def binomial(N,k):
b = ((-1.)**(k)*factorial(N))/(factorial(k)*factorial(N-2.*k))*((2.*x)**(N-2.*k))
return b
x=np.arange(-4,4,.1)
plot(binomial(N,k))
show()
I have tested my factorial function and it does find a factorial of an input. I just cannot figure out where I am going wrong.