# Help me find a mathematical formula.

July 12, 2006 4:31 PM Subscribe

Help me figure out a mathematical formula I need.

I need a formula. I'm going to input the numbers 1, 2, and 3. I need the formula to return 998, 2002, and 3012 respectively. What is the formula?

To get you going at what I'm shooting for, here are two examples.

Let's say instead, that the numbers I needed returned were 2, 4, and 6

So the formula would be 2*x. (2 times x)

Like this:

2 * x = y

When we put in 1, 2, and 3, for x, we get 2, 4, and 6 for y.

if x = 1, y = 2

if x = 2, y = 4

if x = 3, y = 6

Second example.

I need 4, 9, and 14

So the formula (or 'a' formula that works) is (5*x)-1 = y

x=1, y=4

x=2, y=9

x=3, y=14

Get it?

So, the numbers I need are 998, 2002, and 3012.

What's the formula?

I've come to a solution, probably one of many possible solutions. But I had to do it in a roundabout, manual, hit and miss kind of way. What would be the 'correct' way to solve something like this? Some sort of systemic way. How are these types of things solved by people with extensive math skill?

I need a formula. I'm going to input the numbers 1, 2, and 3. I need the formula to return 998, 2002, and 3012 respectively. What is the formula?

To get you going at what I'm shooting for, here are two examples.

Let's say instead, that the numbers I needed returned were 2, 4, and 6

So the formula would be 2*x. (2 times x)

Like this:

2 * x = y

When we put in 1, 2, and 3, for x, we get 2, 4, and 6 for y.

if x = 1, y = 2

if x = 2, y = 4

if x = 3, y = 6

Second example.

I need 4, 9, and 14

So the formula (or 'a' formula that works) is (5*x)-1 = y

x=1, y=4

x=2, y=9

x=3, y=14

Get it?

So, the numbers I need are 998, 2002, and 3012.

What's the formula?

I've come to a solution, probably one of many possible solutions. But I had to do it in a roundabout, manual, hit and miss kind of way. What would be the 'correct' way to solve something like this? Some sort of systemic way. How are these types of things solved by people with extensive math skill?

I get a formula of 995*X + 3X^2 = Y, which fits for your values. There are an infinate number of solutions to this problem, so you usually restrict the type of equations you are allowed to include in the solution. There is no "best" answer or solution without knowing more about the problem. Typically you have a model describing the relationship between X and Y and then find the necessary information to apply that model.

Here the model I used was a polynomial ( 1 + X + X^2 ), and used regression to find the solution, with the setup

[ 1 X X^2 ] * B = Y

A polynomial solver would do just as good.

posted by phatboy at 4:44 PM on July 12, 2006

Here the model I used was a polynomial ( 1 + X + X^2 ), and used regression to find the solution, with the setup

[ 1 X X^2 ] * B = Y

A polynomial solver would do just as good.

posted by phatboy at 4:44 PM on July 12, 2006

JMOZ: am I missing something?

1*1007 - 10 == 997

2*1007 - 10 == 2004

3*1007 - 10 == 3011

You haven't fit any of his values! I get m = 1004, b = -6; but that only fits the first two and not the third.

I suspect that phatboy is right. gummo, you need to provide a further constraint before this problem has a unique solution.

posted by sbutler at 4:54 PM on July 12, 2006

1*1007 - 10 == 997

2*1007 - 10 == 2004

3*1007 - 10 == 3011

You haven't fit any of his values! I get m = 1004, b = -6; but that only fits the first two and not the third.

I suspect that phatboy is right. gummo, you need to provide a further constraint before this problem has a unique solution.

posted by sbutler at 4:54 PM on July 12, 2006

In this case, the fact that the three points are so close to being collinear would make me suspect that there was a slight error in getting the original numbers - wherever gummo got them from.

posted by vacapinta at 5:00 PM on July 12, 2006

posted by vacapinta at 5:00 PM on July 12, 2006

You can fit any series of points to a power series (a sum over integer powers of your "x" coordinate), a fourier series (a sum over trig functions with different periods), or to a number of other expansions. Any of these series, for a finite number of points, will have an infinite number of solutions (as phatboy pointed out)

Assuming you're interested in a power series, for 3 points, you will always be able to get an exact solution with a 2nd order polynomial (and in general, for n points, you need an (n-1)th degree polynomial), but as pointed out by JMOZ, these points happen to be colinear so 1st order works.

There are a number of fitting algorithms computers use to solve these problems, but no simple analytical "correct" way to arrive at a solution.

posted by njgo at 5:04 PM on July 12, 2006

Assuming you're interested in a power series, for 3 points, you will always be able to get an exact solution with a 2nd order polynomial (and in general, for n points, you need an (n-1)th degree polynomial), but as pointed out by JMOZ, these points happen to be colinear so 1st order works.

There are a number of fitting algorithms computers use to solve these problems, but no simple analytical "correct" way to arrive at a solution.

posted by njgo at 5:04 PM on July 12, 2006

Just for info,

With three data points, almost any three element function can be used to generate the Y values. For example,

-.4476 + 1004.5*X - 7.177*sine(X) works just as well (to a few decimal places), even though the function is stupid looking.

as does

933.75*sqrt(X) + 68.8775*e^X - 78.9635* tan(X), which is even uglier.

This is why you need to know more about the problem. You can always fit data to a model, but that doesn't mean the model is good!

posted by phatboy at 5:05 PM on July 12, 2006

With three data points, almost any three element function can be used to generate the Y values. For example,

-.4476 + 1004.5*X - 7.177*sine(X) works just as well (to a few decimal places), even though the function is stupid looking.

as does

933.75*sqrt(X) + 68.8775*e^X - 78.9635* tan(X), which is even uglier.

This is why you need to know more about the problem. You can always fit data to a model, but that doesn't mean the model is good!

posted by phatboy at 5:05 PM on July 12, 2006

For three numbers, there's no guaranteed linear solution. You need at least a second-order polynomial to guarantee a solution. In general, for n points, you need a polynomial of degree (n-1) to fit them. The two cases you mention [(1,2);(2,4);(3,6)] and [(1,4);(2,9);(3;14)] are special cases, since they can both be fit by a 1st degree polynomial (a line).

A polynomial of sufficiently high degree can be made to fit any data set perfectly. Most people who deal with these sorts of things wouldn't try to just fit equations to numbers willy-nilly; they'd try to get some understanding of the system they're trying to describe and develop a model with some physical reality to it.

posted by mr_roboto at 5:12 PM on July 12, 2006

A polynomial of sufficiently high degree can be made to fit any data set perfectly. Most people who deal with these sorts of things wouldn't try to just fit equations to numbers willy-nilly; they'd try to get some understanding of the system they're trying to describe and develop a model with some physical reality to it.

posted by mr_roboto at 5:12 PM on July 12, 2006

If you are looking for a linear function - that means you are just multipling x by a number and then adding or subtracting another number, then there are none that exist for 998, 2002, and 3012.

How to check? Just subtract each number from the next. The results should all be the same if a linear function exists.

e.g

2002- 998 = 1004

3012 - 2002 = 1010 which doesnt equal 1004

posted by zaebiz at 5:37 PM on July 12, 2006

How to check? Just subtract each number from the next. The results should all be the same if a linear function exists.

e.g

2002- 998 = 1004

3012 - 2002 = 1010 which doesnt equal 1004

posted by zaebiz at 5:37 PM on July 12, 2006

I double-checked it by hand and 3x^2+995x is indeed the 2nd-degree solution, like jplank and phatboy said.

Unless this is some kind of riddle where the answer depends on some bizarre non-mathematical trick.

posted by wanderingmind at 6:13 PM on July 12, 2006

Unless this is some kind of riddle where the answer depends on some bizarre non-mathematical trick.

posted by wanderingmind at 6:13 PM on July 12, 2006

I think I typoed the values I used and just happened to get a linear fit.... Pardon my incorrect linear fit.

posted by JMOZ at 6:27 PM on July 12, 2006

posted by JMOZ at 6:27 PM on July 12, 2006

Yes the equation detailed by JMOZ above

y=1007x - 10

is the "best fit" line. It is as close as you will get to a straight line fit (and it's "almost" a straight line).

Easiest way to do this is use Microsoft Excel.

posted by zaebiz at 9:59 PM on July 12, 2006

y=1007x - 10

is the "best fit" line. It is as close as you will get to a straight line fit (and it's "almost" a straight line).

Easiest way to do this is use Microsoft Excel.

posted by zaebiz at 9:59 PM on July 12, 2006

The one phatboy posted is good. It's close to what I came up with, but cleaner. For the record, here is the one I had, but like I said, I didn't do anything cool to get it. (Like polynomial and regression whatever).

((998 * x) - 6) + (3*(2^x))

posted by gummo at 10:09 PM on July 12, 2006

((998 * x) - 6) + (3*(2^x))

posted by gummo at 10:09 PM on July 12, 2006

"Most people who deal with these sorts of things wouldn't try to just fit equations to numbers willy-nilly; they'd try to get some understanding of the system they're trying to describe and develop a model with some physical reality to it."

And just for the record, I was writing a little piece of code, and needed those three numbers (for reasons unnecessary to get into) and figured rather than code a list in there, I'd just plop a formula that would turn my 1, 2, and 3 into the numbers I needed. That sent me off on a time eating tanget about discovering formula to fit data sets. Which ended here.

posted by gummo at 10:16 PM on July 12, 2006

And just for the record, I was writing a little piece of code, and needed those three numbers (for reasons unnecessary to get into) and figured rather than code a list in there, I'd just plop a formula that would turn my 1, 2, and 3 into the numbers I needed. That sent me off on a time eating tanget about discovering formula to fit data sets. Which ended here.

posted by gummo at 10:16 PM on July 12, 2006

This thread is closed to new comments.

998 = m*1 + b

2002 = m*2 + b. Solve for m and b algebraically. Then, check if 3012 = m*3 + b. (In this case, it will be if m = 1007 and b = -10.

If it doesn't work, the three points aren't linear and you'd need to fit a different type of formula. (quadratic, for example).

posted by JMOZ at 4:42 PM on July 12, 2006