0

For a game I'm making, I'm trying to create a logarithmic equation between starting points I know. I've done a lot of research, but haven't found anything too helpful. The points are: ( 0, .9, 1) ( 25, 1, 1) (100, 2, 1) ( 0, .8, 2) ( 25, 1, 2) (100, 4, 2) ( 0, .7, 3) ( 25, 1, 3) (100, 6, 3) ( 0, .6, 4) ( 25, 1, 4) (100, 8, 4) ( 0, .5, 5) ( 25, 1, 5) (100, 10, 5)

where 0 <= x <= 100, .5 <= y <= 10, 1 <= z <= 5

If the inclusion of z is too difficult, I could write a separate equation for each value of z, but knowing how to write the equation (with exact coefficients) passing through all 3 of the values for each value of z is most important to me.

To clarify, as long as I know how to create a logarithmic equation in any format for, for example, ( 0, .9) ( 25, 1) (100, 2) my question will have been answered.

  • When you say "a logarithmic equation", just what sort of equations are you refering to? For example, something like $y = A\log(x) + B$? – Paul Sinclair Nov 11 '18 at 22:48
  • The format is irrelevant so long as it acts like a logarithm tends to - a relatively fast increase in the beginning that quickly slows. – Trentin Nov 11 '18 at 22:57
  • I'm willing to exclude a z value because this equation models the effect of something at different experience levels, but the z value would allow it to function across all 5 variants, so that the starting point is 1-(.1z), y = 0 at x = 25, regardless of the z value, and at x = 100 y = 2z. – Trentin Nov 11 '18 at 23:01

1 Answers1

0

Assume the form $$y = A\ln(x + B) + C$$

I am using base $e$ for the logarithm, but you could use any base. The only difference would be that the value of $A$ would change.

This gives us three unknowns $A, B, C$ to find. For each $z$, you have three points, which gives us three equations. For $z = 0$, these are:

$$0.9 = A\ln(B) + C\\1 = A\ln(25 + B) + C\\2 = A\ln(100 + B) + C$$

We can convert this to exponential equations. To simplify their form, let $u = e^{0.1/A}$ and $v = u^{-C}$.

$$B = vu^9\\B + 25 = vu^{10}\\B + 100 = vu^{20}$$

We can eliminate $B$ by taking differences: $$25 = vu^9(u - 1)\\75 = vu^{10}(u^{10}-1)$$Taking a ratio eliminates $v$. $$3 = \frac {u(u^{10}-1)}{u - 1}$$ or $$u^{11} - 4u + 3 = 0$$ Solving (try Newton's method) gives $u$, then $$v= \frac {25}{u(u^9 - 1)}\\B = vu^9\\C = -\log_u v = -\frac{\ln v}{\ln u}\\A = \frac {0.1}{\ln u}$$

Similar methods can find $A, B, C$ for your other values of $z$. It isn't pretty, but it should work.

Paul Sinclair
  • 43,643
  • As long as the answers are exact, I'm more than happy with the solution. I'll try to work those out and see what I can't come up with. – Trentin Nov 12 '18 at 03:49
  • You are not going to get an exact answer because you need a root of the $u$ polynomial other than $1$ (which is a false solution introduced by the steps I took). There are no other rational solutions, and you are not going to find a closed form for an irrational solutions. However, you can estimate $u$ and the rest to any accuracy that you have the patience and resources to find. – Paul Sinclair Nov 12 '18 at 03:54
  • Ah, as it seems, they are not. Unfortunate, but at the very least I can get extremely close and define the end behavior in the program itself. That won't be hard. – Trentin Nov 12 '18 at 04:05
  • Wolfram Alpha finds two other real solutions but only the positive one will work for you. – Paul Sinclair Nov 12 '18 at 04:10
  • So, v = 25 / u(u^9 - 1). However, u can only be equal to 1 or approximately .763. That means that v will be negative or undefined, and assuming we go with the negative, we cannot take the natural log of v to get C. Am I just messing up in my math, or am I going about solving it incorrectly? – Trentin Nov 12 '18 at 04:30
  • I get (using Wolfram Alpha) $$u = 0.76270098447940118579, \v = -29.9155544068569055127050154,\ B = -2.61267757985448702752132$$, but since $v < 0$, its logarithm will be complex, not real. Unfortunately, it may mean that there is no formula of the form I started with that will fit your points. I'll have to see what else is possible, but tomorrow, as it is late here. – Paul Sinclair Nov 12 '18 at 04:31
  • Should it become too difficult, I have discovered that I can easily create 2 equations that are both equal to 1 at x = 25 and substitute in variables that I can easily find. For example, after x = 25, the function y = (e^(ln(2z)/75)^(x-25) is equal to exactly 2z at 100, what I want, and before x = 25 it can be modeled as (1-.1z)(e^(ln(1-.1z)/25))^x, being exactly equal to 1. This being for a program, the algorithm won't have to be too complex at all to account for the 2 equations, and still covers every z value I needed it to. – Trentin Nov 12 '18 at 04:45
  • The problem here is that logarithmic shaped functions are concave downward, but the three points we are trying to fit them too require concave up – Paul Sinclair Nov 12 '18 at 13:32
  • That is a fair point - the equations I'll probably settle on using or more to the effect of modified exponentials than logarithmics. – Trentin Nov 12 '18 at 17:03
  • Actually, if you are just looking for the general shape, you might want to consider fractional linear transformations. That is, equations of the form $$y = \frac {ax + b}{x + c}$$. The math is a lot easier, and it easily handles both concave up and concave down. – Paul Sinclair Nov 13 '18 at 00:38