0

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?

Zheyuan Li
  • 71,365
  • 17
  • 180
  • 248
Jan
  • 343
  • 2
  • 16
  • 1
    In your example two points have the same x coordinate. Is this a typo? – lisyarus May 29 '16 at 11:06
  • I'm voting to close this question as off-topic because it is about [math.se] instead of programming or software development. – Pang May 30 '16 at 02:23
  • 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. IMO – Jan May 30 '16 at 10:33

2 Answers2

2

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.

Community
  • 1
  • 1
Zheyuan Li
  • 71,365
  • 17
  • 180
  • 248
1

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.

NEU_shi
  • 11
  • 2
  • With y-values up to 50 the third point does not seem to influence the y value at 7. y-values larger than 50 seem to influence values at x=7 proportional (y_3-=5-->y-=5) maybe that is is the nature of lagrange polynomials 2nd degree – Jan May 29 '16 at 10:18