# Need help with polynomial fitting

1. Jun 1, 2004

I have two polynomials fit to two different sets of data points. What I need to know is if there is a way to obtain a polynomial such that it will minimize the distance between all the points on both the other polynomials?

2. Jun 1, 2004

### AKG

If you have polynomials p(x) and q(x), maybe try the polynomial r(x) = [p(x) + q(x)]/2. Just a suggestion...

3. Jun 1, 2004

That would just be an average polynomial. I don't know if that would necessarily be a polynomial that minimizes the distance between all points. I'm thinking along the lines of like the best fit line in linear regression. It will come close to some points but far from others, but it is is the closest it can be to all points. Same here with my two polynomials.

4. Jun 1, 2004

### Gokul43201

Staff Emeritus

If you have two fixed polynomials that you have fit to the data sets, then the distances between their points is fixed. Then I don't see what the role of the third polynomial is.

If there is no third polynomial and you just want to fit 2 polynoms to the data sets such that the distance between the curves is minimized, then do you care about the individual errors in each of the fits ? If you don't care about the errors, then your solution is a single polynomial fitting both data sets - i.e treat them as a single data set, and do a least squares fit.

If you "also" care about the individual errors, then you might perhaps want to minimize something like the sum of the errors and the distance between curves, i.e. :

$$minimize {(y1_n - y1(x1_n))^2 + (y2_n - y2(x2_n))^2 + (y1_n - y2_n)^2}$$

P.S : some context would help...what do you want to achieve ?

Last edited: Jun 1, 2004
5. Jun 1, 2004

Ok, sorry about the phrasing. I'll use some numerical examples.

Say I have a set of numbers {2,6,8,5,7}. The 2 occurs at x=1 and likewise onwards (i.e. x = 5, y =7). From these points, assume I have a polynomial that fits the distribution. Then, let us say I have another set of numbers {1,4.6,7,9,5} again the first number occurs at x=1 and so on. Then I obtain a polynomial of the same degree that fits the distribution as well.

Now, I realize that I could treat this all as a single data set, so that at x = 1 I have a y value of 2 and 1 and so on. Unfortunately, I can't figure out how to do this in Excel or Mathematica. Alternatively, I also have both equations for the polynomial. What I need is a third polynomial such that for all the x values from 1 to 5, the 3rd polynomial has its y values such that they are a minimum distance away from the other two data points. I know that basically this curve is going to be inbetween the other two, but I just don't know how to generate it. Or how to set up a program to allow for relations instead of functions (that is 2 y values for a single series).

6. Jun 2, 2004

### matt grime

you still arent' being specific enough: what do you mean by minimum distance away? the obvious and, as far as it is stated, reasonable solution is a polynomial passing through the points {1.5, 5.3, 7.5,7,6} in the example given, by averaging the y values.

7. Jun 2, 2004

### Gokul43201

Staff Emeritus
If you are wondering whether the "average polynomial" is really the one that minimizes the sum of squares of distances...wonder no more. It IS the one. Think about what happens to this sum of squares as a point moves away from the midpoint between 2 y's. You'll see that the sum only gets bigger. You can check this using lagrange multipliers and minimizing - if you want.

It's still not clear what you are trying to do. Are you attempting some form of forecasting ? This would explain why you have more than one y for the same x.

8. Jun 2, 2004

Correct, I am indeed trying to forecast. And ok, that does make sense, about the average polynomial being the correct one.

9. Jun 16, 2004

### sailor62

Hello,
I'm new to the forum. This is the more interesting forum I ever found!

I have a similar question: given two bidimensional curves in the space, find the Rototraslation that bring one curve as closest as possible (following a non specified notion of distance) to the other.

thanks,

10. Jun 16, 2004

### matt grime

no answer but plenty of questions:

what on earth is a bidmensional curve, what is 'the' space, what is a rototranslation exactly, and how do you expect someone to minimize an un specified quantity?

11. Jun 16, 2004

### Gokul43201

Staff Emeritus
Do you have z1(x,y) and z2(x,y) ?

And do you want to find (x0,y0), phi, that minimizes

SUM[z1(x_i,y_i) - z2(x0 + x_i cos(phi) +y_i sin(phi), y0 + y_i cos(phi - x_i sin(phi) ) ] ?

This is my best guess from the info provided.