The downward recursion of the golden ratio (Project 1.3) may be done as follows:
y2 = 0. # y_{n+1}
y1 = 1. # y_n
nmax = 50
yn = []
for i in range(nmax):
y0 = y2 - y1 # y0 is y_{n-1}
yn.append(y0)
y2 = y1 # reseed
y1 = y0
# reverse, scale, using NumPy array
yn = yn[::-1] # or yn.reverse() for Python 3.x
yn = np.array(yn)/yn[0] # elementwise op (vector)
One can now plot the relative error.
Things to try: One should be able to obtain the positive phi series in upward recursion with arbitrary initial seeds also.
Try y0=0, y1 = 1., and y2=y1+y0 for nmax iterations (say nmax=50). Scale the series so the last element is correct, i.e., multiply it by phi**(nmax+1)/yn[-1]. Compare with the exact series and plot the error. What do you see? why?