Find R in a Finite Geometric Series

programmingsequences-and-series

Given a s and the amount of terms n, is it possible to find the common ratio of a finite geometric series?

$$\sum_{i=1}^n r^i = s$$

I've been able to solve the equation up to

$$\frac{r^{n+1} – r}{r-1} = s$$

but I have no idea how to reduce this further an a way a computer can understand. The closest answer(Geometric series : Find common ration 'r') I can find is to approximate the solution to
$$r^n=s$$
But this number is way to inaccurate for my use case. Since wolfram alpha seems to be able to solve these types of problems, I am hoping there is some simple formula I can use to get the answer I need or at least a better approximation.

Best Answer

As you properly wrote it, you end with a polynomial of degree $n+1$ which cannot be solved analytically if $n >4$.

So, you need a numerical method (Newton being probably the simplest).

Consider that you are looking for the zero of function $$f(r)=r^{n+1}- (s+1)r+s$$ for which $$f'(r)=(n+1)r^n-(s+1)\qquad \text{and} \qquad f''(r)=n(n+1)r^{n-1}$$ The first derivative cancels at $$r_*=\left(\frac{s+1}{n+1}\right)^{\frac{1}{n}}$$ which corresponds to a minimum (by the second derivative test).

To get an estimate, use a Taylor expansion around this point and, solving, use $$r_0=r_*+\sqrt{-2\frac{f(r_*)}{f''(r_*)}}$$ and Newton iterates wil be $$r_{n+1}=r_n-\frac{f(r_n)}{f'(r_n)}$$

Let us try for $n=20$ and $s=123456789$. The iterates are $$\left( \begin{array}{cc} n & r_n \\ 0 & 2.66442 \\ 1 & 2.56586 \\ 2 & 2.50137 \\ 3 & 2.47667 \\ 4 & 2.47363 \\ 5 & 2.47359 \end{array} \right)$$

Comparing Newton, Halley and Householder iterates $$\left( \begin{array}{cccc} n & \text{Newton} & \text{Halley} & \text{Householder} \\ 0 & 2.6644202 & 2.6644202 & 2.6644202 \\ 1 & 2.5658566 & 2.5062787 & 2.4809286 \\ 2 & 2.5013675 & 2.4738521 & 2.4735928 \\ 3 & 2.4766670 & 2.4735928 & \\ 4 & 2.4736339 & & \\ 5 & 2.4735928 & & \end{array} \right)$$