Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Let's say I have these 7 natural numbers (all between 0 and 255):

255, 23, 45, 32, 87, 52, 146

How can I find a function F(x) that, once computed, gives me back these values, ie.

f(1) = 255
f(2) = 23
f(3) = 45

I'm not sure what's the technical term to use for this, but I trust you got the picture.

All the above numbers are just examples (except that all values are natural number between 0 and 255).

All I really care is that I need the simplest possible function that can give me such result, be it polynomial, quartic or any other type of function.

I used to be good at math, but it's been at least 10 years since I took my last math class, so please bear with me!

Thanks in advance!

share|cite|improve this question
Lagrange interpolation provides a nice general polynomial answer. However, suppose that $f(1)=2$, $f(2)=4$, $f(3)=8$, and so on. Then $f(n)=2^n$ is a simple formula, while the Lagrange interpolation polynomial is fairly messy. – André Nicolas Mar 17 '12 at 17:50
up vote 4 down vote accepted

Maybe you want to use Lagrange interpolation. This formula gives the polynomial with the smallest degree that fits your data points exactly. You can find the formula for the Lagrange polynomial at the link, and also there are online calculators that will calculate it for you.

For instance, when I plug your data points [1, 255], [2,23], [3,45], [4,32], [5,87], [6,52], [7,146] into this calculator, I get back the result:

$$f(x)={1291x^6-31029x^5+296455x^4-1434195x^3+3689254x^2-4761696x+2423520\over 720}$$

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.