Why do i get differ results?

Ef pol=5 then Dimension_of_pol = pol+1

Code: Select all

`Dimension_of_pol = 5+1 #My actually dimension of the polynom must be greater in +1 cause the range function give me only last degree`

X_val = [-1. -0.85714286 -0.71428571 -0.57142857 -0.42857143 -0.28571429

-0.14285714 0. 0.14285714 0.28571429 0.42857143 0.57142857

0.71428571 0.85714286 1. ] #My array of x

Arr_X_in_power__=[[x**i for i in reversed(range(Dimension_of_pol))] for x in X_val]

Y_val = [4.898587196589413e-16, 1.5636629649360598, 1.9498558243636472, 0.867767478235116, -0.8677674782351165, -1.949855824363647, -1.56366296493606, 0.0, 1.563662964936059, 1.9498558243636477, 0.8677674782351188, -0.867767478235116, -1.9498558243636468, -1.563662964936061, -4.898587196589413e-16]#My array of y

Code: Select all

`#y is the function 2*sin(2*pi*x)`

And for this purpose i use 2 function from numpy-library

Code: Select all

`X_val = np.array(X_val)`

Y_val = np.array(Y_val)

Arr_X_in_power__ = np.array(Arr_X_in_power__)

1-way is https://docs.scipy.org/doc/numpy/reference/generated/numpy.linalg.lstsq.html

Code: Select all

`w = np.linalg.lstsq(Arr_X_in_power__, Y_val)[0]`

print w

2-way is https://docs.scipy.org/doc/numpy/reference/generated/numpy.polyfit.html

Code: Select all

`coefs = np.polyfit(X_val, Y_val, Dimension_of_pol-1)`

print coefs

And i get various results:

Code: Select all

`#if i use np.linalg.lstsq`

[ 2.46592817e+01 -1.77635684e-14 -3.18031627e+01 -1.98489667e-14

7.39286826e+00 -3.87504418e-14]

#if i use np.polyfit

[ 2.46592817e+01 6.43490116e-15 -3.18031627e+01 -1.28060546e-15

7.39286826e+00 3.79883424e-16]