Skip to main content
9-Granite
January 27, 2022
Solved

Polyfit

  • January 27, 2022
  • 2 replies
  • 2923 views

I defined a function of x and y and plotted it. Later I am calculating matrix values for the function and trying to create a second function to fit the points. My belief was it should result in the first function but the second function deviated from first by large margin. How to rectify this? 

 

 

Best answer by ttokoro

Here is my Prime 7 sheet.

image.png

2 replies

ttokoro
21-Topaz I
21-Topaz I
January 28, 2022

You only use x=y's 21 points (green plot) of the function to polyfit it. 

Using all 441 points data to polyfit function, we get the next plot. Yellow plot is polyfit(,U,V, 2) and Red plot is polyfit(,U,V, 3). Polyfit area expands to -15,-14.5..15 for both x and y data.

image.pngimage.png

t.t.
9-Granite
January 28, 2022

Can you please share the updated worksheet

25-Diamond I
January 28, 2022

While ttokoro is looking for his missing worksheet here are my 2 cents

Here you see in blue the points which you provided for polyfit to find a fitting surface and you see that polyfit succeeded in finding a surface of third order through all your points 😉

Werner_E_0-1643410736542.png

 

If you provide a full mesh of points you get the result you expected.

Werner_E_1-1643410765960.png

 

You may also use "polyfitc" to look for the factors which polyfit finds

Werner_E_2-1643410883308.png

The -0.2 in the row with "AAB" is the coefficient of x^2*y, etc.

 

Prime worksheet attached

 

 

25-Diamond I
January 29, 2022

One additional remark:

The 21 points you used were too special (because x = y for all of them) but normally 10 random points should suffice to define the cubic:

Werner_E_0-1643425563771.png