Exponential Regression: how to get a formula from a given pattern

738 Views Asked by At

I'm trying to code a computer script (in Java) that returns an array of numbers that follows a certain pattern.

enter image description here

The numbers should be: 0, 110, 650, 1500, 2800, 4800, .., 3474606000, 3703616000

I'm not a math person (not familiar with the technical terms), so i'll show you what I came up with using Java programming langage, hopefully you guys can help. Here's my formula so far:

for(i=0; i<=200; i++)
    add( pow(i, 2) + 4 * i ); //Translates to: (x^2)+4i

How can I tweak this, so it returns the numbers expected in my example please ?

3

There are 3 best solutions below

2
On BEST ANSWER

Your best bet is to just store the values in an array, and when you want a value, access the array element at the index, i.e. a[1] for level 1, a[2] for level 2... a[199] for level 199. There's probably no nice formula for this problem. Here's why.

Launching off from Peter's answer, let's assume you want to recreate the table he linked with a closed form formula. Looking at some plots is instructive. Scaling the "experience" on a logarithmic scale:

Experience vs. Level

On a log-log scale:

Experience vs. Level 2

If this function had a nice expression in powers or exponentials, a nice smooth curve or straight lines would be apparent to the eye in plots like this. Instead, we see a subtly lumpy function in both cases. This indicates to me that this function likely wasn't generated by one simple expression of the level number. The last few levels, starting at 187 or so, have an approximately constant 6.7% experience increase per level, apparent from that part of the curve looking like a straight line in the first plot. You could contrive a function that fits this function, but the values probably weren't actually generated by this formula.

0
On

iIf you add up $$\sum_{i=0}^u (i^2+4i) = \frac{u(2u+13)(u+1)}{6}$$, the result is a polynomial in the upper limit, not exponential. The values are 5, 17, 38, 70 at u=1, 2, 3 etc and not related to the values you're trying to reach at.

1
On

If you want an expression matching particular sequence of numbers, it's certainly useful to include more than first few numbers followed by a gap of unknown length and a bunch of "last" few numbers. A bit of Googling suggests that you're trying to get the numbers matching the experience required for level and got pointed to the term "Exponential regression" by Stack Overflow.

Based on a quick look at the numbers on the "level" page I mentioned above, I believe they were made made partially ad-hoc, rather than by a simple formula. One indicator of this observation is related to the consecutive differences between levels. One would expect this difference to grow with higher levels (which it does) and the rate of growth should either accelerate or slow down all the time (this depends largely on the game mechanics), rather than varying between going up and down. For example, look at levels 15-19. The differences for moving from one to the next one are 14, 16, 24 and 27 thousand XPs, while the rate of growth increases by 2, 8 and 3 thousands; increasing and then decreasing again (followed by more increases and occasional decreases too).

Of course, this is not a proof that the data is not created by some formula. In fact, it's always possible to find an expression (a polynomial, even) which matches the finite number of given values... but such formula might be too unwieldy for any actual calculation and if you're only interested in the specific values, storing them in an array and just looking the particular value up might be much, much simpler.

Perhaps if you indicated why you actually prefer one "formula" to having the array, it might be possible to find something that matches your expectations well enough, even though not being absolutely perfect match for the data.