Math(s) question

Discussion in 'Spigot Plugin Development' started by novucs, Oct 5, 2016.

  1. I know this isn't technically plugin development, though I came across this problem while developing a plugin and has been bugging me for a while now. How could you non-programatically resolve the common ratio of a geometric series when provided the sum, initial and number in sequence?

    Relevant equation:

    S: Sum of series
    a: Initial value
    r: Common ratio
    n: Number in sequence to count up to

    In this case, we need to resolve the equation for "r".
  2. What variables are actually known?
  3. S, a and n. I am aware this could be worked out programmatically, though I would really like to know if there is anything out there to resolve the common ratio in one short but sweet equation.
  4. Shouldn't you be able to rewrite it to "r = ..."?
  5. Good Luck With Your Math Expidition! :p I Hope You Do Spigot Proud! :D
    • Funny Funny x 1
  6. That is what I have been attempting, and what I'm asking for in this thread. Apologies if my original post was hard to deconstruct. I would appreciate if you or anyone else could help try to work that out for me.
  7. I think he's trying to find what "r" would equal to, so you are solving for "r" and in order to do that it needs to equal to "s"

    @novucs Don't we need to know what these variables are storing what values so we know what's what?
  8. No, all I need is the equation above to be written to solve "r" instead of "S". It's an algebra question.
  9. You wrote the equation incorrectly.

    You wrote
    Code (Text):
    s=a*((1/r^n)/(1/r)) for r
    when it should be
    Code (Text):
    s=a*((1-r^n)/(1-r)) for r
    When you try and put the correct equation in, it times out and says you need pro, which I don't have :p
  10. From what I'm seeing, there is no possible way to solve the equation for just r. You can get r^n and r on one side of the equation, but since those are two different things, you can't factor out the r and they are left separate.

    The smallest you can simplify it is:
    -ar^n + sr = -a + s
  11. The fact that you have the r as a divisor and dividend and both of them contain two terms (1 and negative r) on the right side of the equation is the issue.
  12. Thanks! I've managed to take it a little further than yours and I think I might have solved it if I'm not missing anything.

    Code (Text):
    s = a((1-r^n)/(1-r))
    s/a = (1-r^n)/(1-r)
    (s-sr)/a = 1 - r^n
    s-sr = a - ar^n
    s + ar^n  = a + sr
    ar^n = a + sr - s
    r^n = (a + sr -s)/a
    n * log(r) = log((a + sr - s) / a)
    log(r) = log((a + sr - s) / a) / n
    r = 10^(log((a + sr - s) / a) / n)
    Edit: Oh I'm dumb, I still have "r" on the other side...
  13. how did you even get this? There's no way you get -a on the right side.

    @novucs don't you happen to have the series instead of the sum? That would probably help a lot.
  14. No, I only have the sum, the first value and the size of the series.
  15. Well first and last might actually help a lot, lol.
  16. Sorry I miss-typed, read again:
  17. @novucs This is a geometrical progression algorithm. Why do you need to get the increment ratio ?
  18. Initially I required it for a closed source level-up plugin I created for a client. The idea was that it costs a % more each time to level up, so my system allowed you to set the level up % cost and the initial price. After creating this, the client told me they wanted a total cost for all levels so I thought it'd be easier to calculate the increment ratio and use that in the config.

    It turns out that task was not exactly simple with normal maths, so I quickly whipped up a script to calculate the increment ratio. Now that issue is past, I cannot stop thinking about a mathematical way around this. So I created this thread more for my curiosity than anything and hoped someone else could find an equation that'll calculate the increment ratio.