I've been wrestling with this 'int' object not callable error for a while and it's still showing up. Here's my code:
import numpy as np
import matplotlib.pyplot as plt
def main_1(n):
"""executes part (a) of problem 1"""
def c_n1(n):
"""Finds constants for n terms"""
sum = 0
for i in range(-n, n+1):
sum += (((-1)**i)*27*np.sqrt(3)*i) / (2*np.pi*(1-9*(i**2)))
return sum
def f_n1(n, func):
"""function values using constant c_n values"""
lmbda = 2
k_n = (2*np.pi*n) / lmbda
sum = 0
x = 1
#range = int(2*x)
t_steps = 100
#delta_t = range / t_steps
f_t_values = np.zeros((t_steps))
t = np.linspace(-x, x, t_steps)
for i in t:
for j in range(-n, n+1):
sum += np.sin(k_n*i)*func(n)
f_t_values[i] = sum
return f_t_values, t
def plot(f_t_values, t):
"""plots f_t function over interval t"""
plt.plot(f_t_values, t)
plt.show
f_t_values, t = f_n1(n, c_n1)
plot(f_t_values, t)
print(f_t_values.shape)
print(t.shape)
main_1(5)
q = np.arange(1,2,100)
print(q.shape)
and here's the error its producing:
TypeError Traceback (most recent call last)
<ipython-input-6-03432c50e4a9> in <module>()
39 print(t.shape)
40
---> 41 main_1(5)
42
43 q = np.arange(1,2,100)
<ipython-input-6-03432c50e4a9> in main_1(n)
34 plt.show
35
---> 36 f_t_values, t = f_n1(n, c_n1)
37 plot(f_t_values, t)
38 print(f_t_values.shape)
<ipython-input-6-03432c50e4a9> in f_n1(n, func)
24
25 for i in t:
---> 26 for j in range(-n, n+1):
27 sum += np.sin(k_n*i)*func(n)
28 f_t_values[i] = sum
TypeError: 'int' object is not callable
I understand most of the time this error means I would have forgotten a '*' and the system reads it as a function 2, for instance, 2(1-2*n) instead of being multiplied. I don't see a mistake of that kind in my code so can someone help me find out what's going on. Thanks :)