I am getting a recursion error from the code below. Could anyone please explain why this is occurring and what a potential fix for the code could be? In this code I am trying to use the original function n1 and use this to find n2 and n3 by using the previous function calculated and storing them in the functions list I created. In other words,i am attempting to do a recursive function inside the for loop. Then I want to evaluate a particular function stored from the list at (h) on the last line.
import numpy as np
f = lambda x: np.sin(10*x)
x0 = 0.5
h = 0.1
n1 = lambda h: (f(x0+h)-f(x0-h))/(2*h)
functions = []
functions.append(n1)
for i in range(0,2):
a = 1/(1-4**(i+2-1))
b = -4**(i+2-1)/(1-4**(i+2-1))
nh = lambda h: a*functions[i](h) + b*functions[i](h/2)
functions.append(nh)
print(functions[1](h))
RecursionError: maximum recursion depth exceeded