1

This is the formula I worked out to use in my game to calculate player experience $x$ needed for level $y$:

C#: $x = (y * (y+1) / 2) * y^{1.5}$

or

$x = y \cdot (\frac{ y + 1 }{2}) \cdot y ^ {1.5}$

This I've been able to work out bits and pieces, but eventually keep getting stuck on having to solve for Y when only X is known. I am also limited on my math vocabulary in English (in addition to not paying enough attention at school previously) and am not familiar with all the learned notations, so most of the explanations that I find are way over my head.

I've worked out the logarithm to handle the exponent, the Cardano Method in this post, teied a few online equation solvers and eventually got to $2y = x\cdot\frac{7}{2}+x\cdot\frac{5}{2}$. However this doesn't result in anything sensible and I'm not sure what is wrong. The main problem is handling multiple use of $y$ on the right side, coupled with the exponent. Is there a somewhat simple way to explain how to work this out?

For example, when Y = 4, X = 80, so how would I get from 80 back to 4?

D3Duck
  • 13
  • Your equations don't match. Can you edit your question? I think the final equation should be $2x=y^{7\over 2}+ y^{5\over 2}$ (which have no simple solution). – N74 Apr 27 '18 at 05:26

1 Answers1

2

The equation write $$x=\frac{1}{2} y^{5/2} (y+1)$$ which corresponds to a polynomial of degree $7$ in $\sqrt y$ and this cannot be solved explicitly.

Numerical method being required, consider that you look for the zero of function $$f(y)= y^{5/2} (y+1)-2x$$ $$f'(y)=\frac{1}{2} y^{3/2} (7 y+5)$$ and use Newton method starting from a guess $y_0$ and obtain the iterates $$y_{n+1}=y_n-\frac{f(y_n)}{f'(y_n)}$$ A reasonable choice seems to be $y_0=(2x)^{2/7}$ (obtained neglecting the $1$ in the equation).

Let us try for your example $x=80$; the iterates would be $$\left( \begin{array}{cc} n & y_n \\ 0 & 4.263326233 \\ 1 & 4.018611856 \\ 2 & 4.000101025 \\ 3 & 4.000000003 \\ 4 & 4.000000000 \end{array} \right)$$

Edit

We can have a quite good estimation of the solution using rational approximation built from Padé approximants around $y0$. $$y=t\,\frac {15+77t+98t^2}{35+105t+98t^2}\qquad \text {where} \qquad t=(2x)^{2/7}$$ The table below shows some results $$\left( \begin{array}{ccc} x& \text{approximation} & \text{exact} \\ 50 & 3.46832 & 3.46724 \\ 100 & 4.28014 & 4.27936 \\ 150 & 4.83593 & 4.83530 \\ 200 & 5.27152 & 5.27097 \\ 250 & 5.63508 & 5.63459 \\ 300 & 5.94993 & 5.94949 \\ 350 & 6.22930 & 6.22889 \\ 400 & 6.48150 & 6.48111 \\ 450 & 6.71211 & 6.71175 \\ 500 & 6.92511 & 6.92477 \\ 550 & 7.12342 & 7.12309 \\ 600 & 7.30925 & 7.30894 \\ 650 & 7.48434 & 7.48404 \\ 700 & 7.65007 & 7.64978 \\ 750 & 7.80756 & 7.80728 \\ 800 & 7.95772 & 7.95745 \\ 850 & 8.10133 & 8.10107 \\ 900 & 8.23904 & 8.23878 \\ 950 & 8.37139 & 8.37114 \\ 1000 & 8.49885 & 8.49861 \end{array}\right)$$ This does not seem to be too bad !

Update

More empirical but simpler), based on a nonlinear regression for $0 \leq y \leq 10$, $$y=t \, \frac{a+b\,t}{1+b\, t}$$ leads to an almost perfect fit with $$\begin{array}{clclclclc} \text{} & \text{Estimate} & \text{Standard Error} & \text{Confidence Interval} \\ a & 0.239090 & 0.000296 & \{0.238509,0.239672\} \\ b & 2.656562 & 0.001130 & \{2.654346,2.658779\} \\ \end{array}$$

  • Thanks for taking the time! So I'm all over the internet now figuring out what all these words mean so I can understand a bit better what you are saying. Meanwhile, could you please clarify how the formula would be written on one line? I need to write it in C# code and this is what I understand from it: y = t * ((15+77*t+98*t^2) / (35+105*t+98*t^2)) and then everywhere it says t I'd go (2*x)^(2/7) That right? It seems to be doing the trick although I have no idea how you figured that out. – D3Duck Apr 28 '18 at 05:44
  • @D3Duck. I had fun with this problem. To code it, for $x$ given, define first $t=(2x)^{2/7}$ and then $y=t,\frac {15+77t+98t^2}{35+105t+98t^2}$ which is only an approximation even if it looks quite good. If you want more accuracy, I could provide you longer and better approximations. Remember that there is a good method to evaluate polynomials with a minimum number of operations. If you want rigor, use Newton method as described in my naswer. Cheers. – Claude Leibovici Apr 28 '18 at 05:50