# Math(s) question

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

1. ### novucs

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=a((1-r^n)/(1-r))

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. ### novucs

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. ### _NotTheWither_

Good Luck With Your Math Expidition! I Hope You Do Spigot Proud! • Funny x 1
6. ### novucs

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. ### novucs

No, all I need is the equation above to be written to solve "r" instead of "S". It's an algebra question.

9. ### Jo_Jo_2000

10. 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 11. ### 567legodude

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

12. 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.

13. ### novucs

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.

Workings:
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...

14. 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.

15. ### novucs

No, I only have the sum, the first value and the size of the series.

16. Well first and last might actually help a lot, lol.