Fitting a function to a sequence of datapoints (quadratic)

225 Views Asked by At

I'm looking for a formula for the next term in a sequence (example from an RPG game).

$\begin{matrix} n & f(n)\\\hline 1 & 29 \\ 2 & 33 \\ 3 & 37 \\ 4 & 41 \\ 5 & 46 \\ 6 & 50 \\ 7 & 55 \\ 8 & 60 \\ 9 & 65 \\ 10 & 70 \\ 11 & 75 \\ 12 & 81 \\ 13 & 86 \\ 14 & 92 \\ 15 & 98 \\ 16 & 104 \\ 17 & 111 \\ 18 & 117 \\ 19 & 124 \\ 20 & 131 \\ 21 & 137 \\ 22 & 145 \\ 23 & 152 \\ 24 & 159 \\ 25 & 167 \\ 26 & 175 \\ 27 & 183 \\ 28 & 191 \\ 29 & 199 \end{matrix}$

Who knows value for $f(30)$, $f(31)$, $f(32)$ etc? What is the formula?

Strictly speaking, there's no reason to assume this pattern repeats, although this certainly looks like it's quadratic. It looks like the values in this sequence are just the result of $0.0814n^2+3.6298n+25.44$, rounded.

Jack Crawford

why not line graph you can see on image below trendline why not - click to view

1

There are 1 best solutions below

4
On BEST ANSWER

Strictly speaking, there's no reason to assume this pattern repeats, although this certainly looks like it's quadratic.

I used Excel to run a quick regression and give me the closest quadratic, and I get this: $f(n) \approx 0.0814n^2 + 3.6298n + 25.44$. It looks like the values in this sequence are just the result of this quadratic, rounded.

Here are the values you had, and here is the value generated by this quadratic for comparison:

$\begin{bmatrix} n & \textrm{data}& f(n)\\\hline 1 & 29 & 29.1512 \\ 2 & 33 & 33.0252 \\ 3 & 37 & 37.062 \\ 4 & 41 & 41.2616 \\ 5 & 46 & 45.624 \\ 6 & 50 & 50.1492 \\ 7 & 55 & 54.8372 \\ 8 & 60 & 59.688 \\ 9 & 65 & 64.7016 \\ 10 & 70 & 69.878 \\ 11 & 75 & 75.2172 \\ 12 & 81 & 80.7192 \\ 13 & 86 & 86.384 \\ 14 & 92 & 92.2116 \\ 15 & 98 & 98.202 \\ 16 & 104 & 104.3552 \\ 17 & 111 & 110.6712 \\ 18 & 117 & 117.15 \\ 19 & 124 & 123.7916 \\ 20 & 131 & 130.596 \\ 21 & 137 & 137.5632 \\ 22 & 145 & 144.6932 \\ 23 & 152 & 151.986 \\ 24 & 159 & 159.4416 \\ 25 & 167 & 167.06 \\ 26 & 175 & 174.8412 \\ 27 & 183 & 182.7852 \\ 28 & 191 & 190.892 \\ 29 & 199 & 199.1616 \end{bmatrix}$

I think that's what you're after. They just round the result at the end.

If you ever want to do this yourself (it's a very useful little trick, and can fit other kinds of functions to your data, too!), just line the columns of data up next to each other in Excel, select them, make a line graph, and then right click on the line and choose the "add trendline" option. From the trend-line menu, you can play around with the different kinds of functions and see if you can find the one that fits your data the best (as you noted in one of your comments above, there are a few properties about this that should point us in the direction of this being quadratic; a degree-2 polynomial), and then select "display equation on chart" and they will give you the equation for the best-fitting trendline. Good luck with your game!

How to fit trendline in Excel