0
votes

I am trying to interpolate a series of data points using 2nd lagrange polinomial. having

point1:(5;100)
point2: (9;17)
point3: (12;17)

and the formula

y=(x-x2)*(x-x3)/(x1-x2)*(x1-x3)*y1+
  (x-x1)*(x-x3)/(x2-x1)*(x2-x3)*y2+
  (x-x1)*(x-x2)/(x3-x1)*(x3-x2)*y3

It is obvious that a quadratic function might not fit the data.. It is just an example.

But i wonder why the value is surprisingly high for x=7. If i am not wrong its y=1500.

Is the above formula correct?

2
In your example two points have the same x coordinate. Is this a typo?lisyarus
I'm voting to close this question as off-topic because it is about Mathematics instead of programming or software development.Pang
It is about interpolation of DATA. Then tell me how to interpolate a time series? On a piece of paper? Surely it IS a programming question. And not as abstract to put it on math. IMOJan

2 Answers

2
votes

answer:

In summary:

  1. For the same x, you can't have two different y values; this violates the definition of a function.
  2. you are missing brackets in your formula! Not (x-x2)*(x-x3)/(x1-x2)*(x1-x3), but ((x-x2)*(x-x3)) / ((x1-x2)*(x1-x3)).
  3. back to 1>, note that the interpolation formula has x3-x2 in the denominator. If you have tied values, you will be dividing 0.
  4. How can you make interpolation on such small data set? Yet you are asking for a quadratic interpolation!

follow-up:

1) fixed it. Accidentally i switched all the x and y values. So the points were in format (y,x).

Ah, haha, no wonder.

2) Thank you! The brackets improved the approximation. Regarding the missing brackets: I got the formula from the accepted answer here: Best way to find Quadratic Regression Curve in Java, but I don't understand this rule.

This is the famous, yet fundamental interpolation: Lagrange interpolation. You can verify its formula at Wolfram mathworld: Lagrange Interpolating Polynomial. I don't give you wikipedia link because this one looks more beautiful.

The link you found must contain a typo. Since you have suggest an edit to fix that, hopefully it will soon get approved.

3) It is a (significant larger (which answers your 4th question) time series. So it is impossible to have tied values.

Yes, time series won't have tied values.

1
votes

formula should be correct.but when x=17,you have two different y value,it's might the cause of the trouble.you can try change anthor x.