%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
n=100
x = np.arange(1,n+1,1)
x = x/n
y = np.random.randn(n)*20+30
plt.plot(x,y)
A = np.vander(x,increasing=True)[:,:5]
plt.imshow(A,aspect="auto")
A_p_inv = np.linalg.inv(A.T.dot(A)).dot(A.T)
plt.imshow(A_p_inv,aspect="auto")
A_p_inv.dot(A)
plt.imshow(A.dot(A_p_inv))
c = A_p_inv.dot(y)
plt.plot(c)
plt.plot(A.dot(c))
n=200
x_ = np.arange(1,n+1,1)
x_ = x_/n
x_ = x_[np.logical_and(x_>=x.min(), x_<=x.max())]
A_ = np.vander(x_,increasing=True)
A_ = A_[:,:len(c)]
plt.imshow(A_,aspect="auto")
plt.plot(x_,A_.dot(c))
plt.plot(x,y,"o")