Skip to content
Advertisement

Polynomial fitting with equal number of data points and coefficients

I am currently experimenting with polynomial fitting using jupyter. The function below returns the least-square polynomial of degree m given the data points in xs with corresponding ys.

JavaScript

Suppose I have the following six data points and fit a polynomial of degree 5:

JavaScript

From my understanding, the resulting curve should pass through every single data point exactly (in fact, the Lagrange polynomial should be the result).

JavaScript

Sample output:

enter image description here

However, this is not the case. The curve is quite far off! What is going on here? Does this have something to do with round-off error? Thanks in advance!

Advertisement

Answer

It seems there was a truncation error! The block of code

JavaScript

should read:

JavaScript

i.e we have to specify the zeros as float.

Moreover, round-off errors can amplify in the process of inverting a matrix. This will particularly be the case when the eigenvalues of the matrix that we want to invert differ significantly in their order of magnitude.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement