In [1]:
%matplotlib inline
In [2]:
import numpy as np
import matplotlib.pyplot as plt

Generate $x$ and $y$

In [3]:
#vjgdruihdiruhgdiuhj
n=10
x = np.arange(1,n+1,1)
x = x/n  
y = np.random.randn(n)*10+30
In [4]:
plt.plot(x,y)
Out[4]:
[<matplotlib.lines.Line2D at 0x10eb21550>]

Vandermonde matrix

In [5]:
A = np.vander(x,increasing=True)
In [229]:
plt.imshow(A)
Out[229]:
<matplotlib.image.AxesImage at 0x116bf6550>

Compute the inverse of $A$

In [230]:
A_inv = np.linalg.inv(A)
In [231]:
plt.imshow(A_inv )
Out[231]:
<matplotlib.image.AxesImage at 0x116c48630>
In [232]:
plt.imshow(A.dot(A_inv))
Out[232]:
<matplotlib.image.AxesImage at 0x116d14828>

Compute $c$

In [233]:
c = A_inv.dot(y)
In [234]:
plt.plot(c)
Out[234]:
[<matplotlib.lines.Line2D at 0x116eb7940>]
In [235]:
plt.plot(A.dot(c))
Out[235]:
[<matplotlib.lines.Line2D at 0x116e13cf8>]

Generate new values, compute $A$ and apply $c$

In [14]:
n=40
x_ = np.arange(1,n+3,1)
x_ = x_/n
#x_ = x_[np.logical_and(x_>=x.min(), x_<=x.max())]
In [15]:
x_<=x.max()
Out[15]:
array([ True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True,  True,  True,  True,  True,  True,
        True,  True,  True,  True, False, False])
In [ ]:
 
In [257]:
x
Out[257]:
array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1. ])
In [258]:
x_
Out[258]:
array([0.1  , 0.125, 0.15 , 0.175, 0.2  , 0.225, 0.25 , 0.275, 0.3  ,
       0.325, 0.35 , 0.375, 0.4  , 0.425, 0.45 , 0.475, 0.5  , 0.525,
       0.55 , 0.575, 0.6  , 0.625, 0.65 , 0.675, 0.7  , 0.725, 0.75 ,
       0.775, 0.8  , 0.825, 0.85 , 0.875, 0.9  , 0.925, 0.95 , 0.975,
       1.   ])
In [259]:
A_ = np.vander(x_,increasing=True)
A_ = A_[:,:len(c)]
In [260]:
plt.imshow(A_)
Out[260]:
<matplotlib.image.AxesImage at 0x1172d4908>
In [261]:
plt.plot(x_,A_.dot(c))
plt.plot(x,y,"o")
Out[261]:
[<matplotlib.lines.Line2D at 0x1173225c0>]
In [ ]: