• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Math formula

Soulkeeper

Diamond Member
I'm working on a software project where I have some numbers output.
I want to find a math formula to fit the numbers to better understand the data.

X Y
3 1
4 4
5 10
6 20
7 35
8 56
9 84
10 120
11 165
12 220
13 286

How would I go about getting a formula that would tell me a Y value given an X ?
I'm not even sure if this is calculus/algebra or what terms i'd google for here.
thanks
 
heh if you were a windows user i'd tell you to dump it into excel and do a scatter plot and then add a trendline

excel says:

i picked polynomial because it looked like it matched

y = 0.1667x^3 - 0.5x^2 + 0.3333x + 5E-11
R2 = 1


edit: look up 'curve fitting'



i think we did this by hand in physics lab a long long time ago
 
Last edited:
heh if you were a windows user i'd tell you to dump it into excel and do a scatter plot and then add a trendline

excel says:

i picked polynomial because it looked like it matched

y = 0.1667x^3 - 0.5x^2 + 0.3333x + 5E-11
R2 = 1


edit: look up 'curve fitting'



i think we did this by hand in physics lab a long long time ago

thanks
I was trying to solve that using this website http://www.johansens.us/sane/education/formula.htm i'd get to 0.1667x^3 But I kept failing at the x^2 step.
 
y = (x^3)/6 - (x^2)/2 + x/3 appears to be correct
your windows app just fudged the numbers a bit

Now I just gotta figure out how to 'curve fitting' or solve similar problems in the future
 
If you just need a rough fit then look up least-squares. Its one of the most basic fits other than linear. You'll end up solving using matrix operations, so that will be how you will code it.

If you need an exact fit then you need the full polynomial interpolation and again solve it using matrix operations. The number of polynomials you need depends on the number of data points. That should be enough to get you headed in the right direction.
 
How do you know, in general, that there would be a function that will fit your data? If the curve is just an approximation, it may not be safe to use it for extrapolating any new data.
 
polynomial interpolation seems to be what I need
my numbers are being generated by loops incrementing based on the loop outside each so an exact fit is certain.
 
How do you know, in general, that there would be a function that will fit your data? If the curve is just an approximation, it may not be safe to use it for extrapolating any new data.

Its really a matter of the initial question. All he needs to find is a function that goes through all those points. A polynomial interpolation will do exactly that.
 
y = (x^3)/6 - (x^2)/2 + x/3 appears to be correct
your windows app just fudged the numbers a bit

Now I just gotta figure out how to 'curve fitting' or solve similar problems in the future


An HP Scientific calculator is able to provide the equation to a set of points and its "Solve" routine is able to provide the Y value for the given X value/input.
 
hmm I see a solve button on my ti-83
Guess i'll have to refigure that out, been over a decade since i've actually used the thing.

thanks everyone
 
How do you know, in general, that there would be a function that will fit your data? If the curve is just an approximation, it may not be safe to use it for extrapolating any new data.
well that depends on the data and which conclusions you want to get, the interpolating function generator doesn't think for you 😛
But if you know that a physical phenomenon behaves approximately in a certain way within your range of operation and you just need the parameters, this should be good enough.

I'm pretty sure this is implemented in Octave (it's the linux Matlab) as well so you could copy their code or at least their algorithm.
 
Last edited:
Its really a matter of the initial question. All he needs to find is a function that goes through all those points. A polynomial interpolation will do exactly that.

In general, that's something you don't want to do. In most cases, you will end up over-fitting the data, and the resulting curve will fail to correctly generalize when presented with new data. What you really want is to find the lowest order model that accurately captures the trends in what may be noisy data.
 
Try this wed based "Polynomial Regression Data Fit" :

http://www.arachnoid.com/polysolve/

Just paste your data pair (ie, X,Y data values) into the "Data Entry" window then press "Solve".

For the data set given, setting the "Degree" =3 results in an almost perfect fit (R^2= 0.9999999999999998).

You will get the graphical fit, polynomial coefficients and the provided application allows to conveniently solve the poly for various selectable values of X.

(Solve for a specific X simply by manually entering the specific value in the "Start" box. )


PS: Recommend you just read your scientific calculator manual as it does all of this in the palm of your hand. In addition, the user typically has the application code used by the calculator and with that, you can just program it on a PC using free DOS "BASIC" (which you can run in a command window in a Windows OS such as XP - I do it all the time).
 
Actually, it is a perfect fit if you did that. Calculators make slight rounding errors. His y-values are the number of balls in a triangular pyramid with x being the number of balls on each edge.
1 is obviously 1
2 along each edge gives a triangular base of 3, plus one on top.
3 along each edge gives a triangular base of 6, then 3 in the middle layer, then 1 = 10
4... base of 10, then 6, then 3, then 1 =20

5... let's see... The base triangle will have 5+4+3+2+1 (arranged like billiard balls), then the 4 sided pyramid of 20 balls resting on top.

6... 6+5+4+3+2+1 plus 5+4+3+2+1 plus 4+3+2+1 plus 3+2+1 plus 2+1 plus 1 = 56 balls.

You can derive a formula for this sum: = x(x+1)(x+2)÷6

Sorry I didn't answer the thread sooner.
 
(x-2)(x-1)x/6

seems to work fine; maybe there is a slight typo in the previous posting.
 
Last edited:
(x-2)(x-1)x/6

seems to work fine; maybe there is a slight typo in the previous posting.
Yes, thanks! I hadn't even looked back at the OPs post - I had focused more on the sequence of y-values: 1,4, 10, 20,... I neglected to notice that the OP started with a value of 3 for x.
x(x+1)(x+2) when x=1 is the same as
(x-2)(x-1)(x) when x=3.

My bad.
 
Thanks for the input guys
I've moved on from this project since, but i'll pull this thread up if I decide to revisit it.
 
How do you know, in general, that there would be a function that will fit your data? If the curve is just an approximation, it may not be safe to use it for extrapolating any new data.

I'm only repeating what some others have said, but in this case it was a perfect fit, verifiable by the fit value. If it were close but not exact, it would have returned something less than 1, such as the 0.9999... that C1 described. I'm guessing it fit so clean because it is academic and the original data were likely generated from a predictable polynomial.

To your second question, this is why if you are writing a technical/research paper where you extrapolate data you need to detail your error budget for the data being described. I work in geophysics and there is virtually never a case where the curve fits the data exactly.
 
Back
Top