""" Example from lectures 29 sept-01 oct. The simplest example of a difference equation, modeling how an invested amount grows over time. """ import matplotlib.pyplot as plt import numpy as np x0 = 100 # initial amount p = 5 # interest rate N = 4 # number of years years = list(range(N+1)) x = np.zeros(len(years)) # Compute solution x[0] = x0 for i in years[1:]: x[i] = x[i-1] + (p/100.0) * x[i-1] plt.plot(years, x, 'ro') plt.xlabel('years') plt.ylabel('amount') plt.show()