""" Ex A.4 from "A primer on..." Compute the value of a loan of size L which is paid back over N months, and also the monthly payment, by solving a system of two differential equations. """ import numpy as np import matplotlib.pyplot as plt L = 100 # initial amount p = 5 # interest rate N = 40 # number of months months = range(N+1) x = np.zeros(N+1) y = np.zeros(N+1) x[0] = L y[0] = 0 for n in months[1:]: y[n] = (p/(12 * 100)) * x[n-1] + L/N x[n] = x[n-1] + (p/(12* 100.0)) * x[n-1] - y[n] plt.plot(months, y, 'bx') plt.xlabel('Months') plt.ylabel('Amount') plt.show() """ Terminal> python loan.py (output is a plot) """