""" Exercise A.4. Very similar to the interest_rate example from the slides/book, but we solve a system of two difference equations, ending up with two arrays: x - the remaining loan after month n y - the amount we pay in month n """ from numpy import * from matplotlib.pyplot import * L = 100 p = 5 N = 36 #months index_set = range(N+1) x = zeros(len(index_set)) y = zeros_like(x) #alternatively y = zeros(len(index_set)) x[0] = L y[0] = 0 for n in index_set[1:]: y[n] = x[n-1]*p/(12*100) + L/N x[n] = x[n-1] + x[n-1]*p/(12*100) - y[n] #plot x as red circles, y as blue + plot(x,'ro') plot(y,'b+') show()