0

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

  • 4
    There's no reason to not assume that the values are arbitrarily chosen – Hagen von Eitzen Jun 05 '19 at 09:16
  • It increases almost regularly, difference between two numbers in turn: 4,4,4,5,4,5,5,5,5,5,6,5,6,6,6,7,6,7,7,6,8,7,7,8,8,8,8,8 – poszkodowany Jun 05 '19 at 09:25
  • It seems like you’ve modified your question to add, well, basically a whole extra question to it. I’m kind of confused. Could you perhaps just make this a new, separate question, or at least format this one in a less confusing way? I think it’s usually against the vibe of stack exchange to edit your question to add a new one after it’s already been answered – Jack Crawford Jun 08 '19 at 22:33
  • Also it looks like you added back some tags that we removed in edit. We removed those tags for good reason, this question is not about elementary number theory, or about pattern matching. Pattern matching is a particular thing in computer science, and none of this has to do with number theory. – Jack Crawford Jun 08 '19 at 22:35
  • If you roll back this question to the previous edit and just post this as a new question (let me know when you have) I’ll be more than glad to help you out with it. – Jack Crawford Jun 08 '19 at 22:40
  • If you're saying that the values yielded by this quadratic (rounded) are not the same as the actual empirical values you observe when you manually go and check the negative values, it's because, as @HagenvonEitzen notes above, there's no reason to assume that these are all generated in some consistent way. If the values you get over the negative range are different to the values you get from the quadratic over the positive range, that's because they must be using a completely different function for those values. As we've said, the game developer can do whatever they want with the sequence. – Jack Crawford Jun 08 '19 at 23:06
  • You probably just have to go and collect some new data and run another regression on it as I described below. – Jack Crawford Jun 08 '19 at 23:06

1 Answers1

4

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

  • I probably meant that, thank you :) but can you show what it looks like for negative values? I want to match the number 19 (and I mark the topic as solved) – poszkodowany Jun 05 '19 at 09:42
  • 1
    Solving $0.0814x^2+3.6298x+25.44 = 19$ and rounding $x$ gives $x = -2$. – Toby Mak Jun 05 '19 at 09:45
  • Sure! You can just use that formula I gave you, as Toby suggested, but here are the values we get for the first few negative inputs, $\begin{matrix} -20 & -14.596 \ -19 & -14.1408 \ -18 & -13.5228 \ -17 & -12.742 \ -16 & -11.7984 \ -15 & -10.692 \ -14 & -9.4228 \ -13 & -7.9908 \ -12 & -6.396 \ -11 & -4.6384 \ -10 & -2.718 \ -9 & -0.6348 \ -8 & 1.6112 \ -7 & 4.02 \ -6 & 6.5916 \ -5 & 9.326 \ -4 & 12.2232 \ -3 & 15.2832 \ -2 & 18.506 \ -1 & 21.8916 \\end{matrix}$ – Jack Crawford Jun 05 '19 at 09:46
  • 1
    Nice explanation ! Using matrix calculations, you would get the exact coefficients $\frac{439}{5394}$, $\frac{45685}{12586}$ and $\frac{15493}{609}$. And $\to +1$. – Claude Leibovici Jun 07 '19 at 11:24