In [1]:
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
In [2]:
year = np.array([1986, 1988, 1990, 1992, 1994, 1996])
price= np.array([133.5, 132.2, 138.7, 141.5, 137.6, 144.2])

M = np.vander(year)
a = np.linalg.solve(M,price)

x = np.linspace(1986,1996,200)
p = np.polyval(a,x)
plt.plot(year,price,'o',x,p,'-')
Out[2]:
[<matplotlib.lines.Line2D at 0x10f0db588>,
 <matplotlib.lines.Line2D at 0x10f0db908>]
In [3]:
year = np.array([1986, 1988, 1990, 1992, 1994, 1996])
year = year / year.mean()
price= np.array([133.5, 132.2, 138.7, 141.5, 137.6, 144.2])

M = np.vander(year)
a = np.linalg.solve(M,price)

x = np.linspace(year.min(), year.max(),200)
p = np.polyval(a,x)
plt.plot(year,price,'o',x,p,'-')
Out[3]:
[<matplotlib.lines.Line2D at 0x10f1ea8d0>,
 <matplotlib.lines.Line2D at 0x10f1eac18>]
In [ ]:
 
In [ ]: