These two sections my code are giving the following error message.
def Simpsons(a, b, n, f, x):
h=(b-a)/n
s = 0.
step = a + h
for i in range(1, int(n/2)):
s += 4*f(x)
#step += 2*h
step = a + 2 * h
for i in range(2, int(n/2 - 1)):
s += 2*f(x)
#step += 2 * h
area = (h/3) * (f(a) + f(b) + s)
return area
and
for i in range(0, len(list_n)):
for j in range(0, len(Functions)):
x = np.linspace(a, b, list_n[i])
error_simp[j, i] = Exact_intergrals[j] - Simpsons(0, 1, list_n[i], Functions[j], x)
print(error_simp)
Give this message:
error_simp[j, i] = Exact_intergrals[j] - Simpsons(0, 1, list_n[i], Functions[j], x)
ValueError: setting an array element with a sequence.
Why is this? everything I have tried does not get rid of it.