Help solving an equation with powers

Jennifer Murphy

Registered Senior Member
I need to solve this equation for both n and r. My algebra is just too rusty after many years away.

B = P*r^n + m*((r^n-1)/(r-1)

Thanks for any help.
 
I need to solve this equation for both n and r. My algebra is just too rusty after many years away.

B = P*r^n + m*((r^n-1)/(r-1)

Thanks for any help.
You have one equation with two unknowns. In general, you need a second (independent) equation relating the two unknowns to get a solution.
 
B=Bonus paid to banker for arranging loan
P=Principal
r some factor (probably) <1
n=years
m=some other factor (??)
?
 
You have one equation with two unknowns. In general, you need a second (independent) equation relating the two unknowns to get a solution.
I guess I didn't state the problem very well. Let me try again.

I actually have 5 unknowns (variables). I will have values for 4 of them and I want to calculate the 5th.

For example, if the equation were 2a+3b=4, I would want to solve it for both a and b:

a = (4-3b)/2
b = (4-2a)/3

If I am given a or b, I can compute the other one. I want to do that for my equation with 5 variables. I've already done it for B, P, and m. I just need it for n and r.

But I think I am starting to remember how to do it. To get n, I need to rearrange the terms and then take logs. I haven;t quite got it yet, but I am working on it. The same approach might work for r.
 
B=Bonus paid to banker for arranging loan
P=Principal
r some factor (probably) <1
n=years
m=some other factor (??)
?
P = initial principle (loan or investment)
r = interest rate (monthly)
m = monthly amount (loan payment (<0), investment deposit (>0), investment withdrawal (<0))
n = number of months
B = Balance after m months
 
$$B = Pr^n + \frac{mr^{n-1}}{r-1}$$

The solution for n is easy enough:

$$n=\left[\log \left(\frac{B}{Pr+m/(r-1)}\right) / \log r\right] + 1$$
 
I have managed to solve the equation for 4 of the 5 variables.

The equation starts off solved for B:

B = P*r^n + m*((r^n-1)/(r-1)

Solving it for P yields,

B(r-1) - m(r^n - 1)​
P = -----------------------
r^n(r - 1)​

Solving it for m yields,

(B-Pr^n)(r-1)​
m = -------------
r^n-1​

And solving it for n yields,

B(r-1) + m​
ln------------------
P(r-1) + m​
n = ----------------------
ln(r)​

I have checked all of these against each other and they seem to be correct.

But I am stumped on how to solve it for r. Any help?
 
$$B = Pr^n + \frac{mr^{n-1}}{r-1}$$

The solution for n is easy enough:

$$n=\left[\log \left(\frac{B}{Pr+m/(r-1)}\right) / \log r\right] + 1$$

Are you sure that's correct? It doesn't seem to agree with my result, which agrees with the other versions.
 
Jennifer:

Sorry. It looks like it must be:

$$B = Pr^n + \frac{m(r^n - 1)}{r-1}.$$

In that case:
$$n=\log \left(\frac{B(r-1)+m}{P(r-1)+m}\right)/\log r$$

which is the same as your expression for n.
 
In general, polynomials of degree 5+ do not admit clean solutions, so solving for r may not be possible. Do you have a reason to expect that this particular form of polynomial is solvable?

Nope, I just want it to! :)

Maybe I'll look into an iterative approach. I know that 1 <= r < 2 and it's most likely very close to 1.

Thanks
 
Nope, I just want it to! :)

Maybe I'll look into an iterative approach. I know that 1 <= r < 2 and it's most likely very close to 1.

Thanks
Fair enough! :) Now that I look at what your equation is actually supposed to represent, I realize that r is a monthly interest rate, which (depending on what kind of loan we're talking about) probably puts it under 1.01. With that in mind, a Taylor expansion will probably serve you well. If we define $$r=1+s$$ and expand the equation in small s,

$$B \approx P(1+ns) + m\frac{ns+n(n-1)s^2/2}{s} + \mathcal{O}(s^2) = P + nm + \frac{n(n-1)}{2}s + \mathcal{O}(s^2)$$

$$r \approx 1 + 2\frac{B-P-nm}{n(n-1)}$$

Someone should probably double-check my algebra there, but the process is pretty straightforward, and you can take the expansion one order higher if you want more precision while maintaining a simple, analytic solution.
 
Approximation might be a better approach.

Let r = 1 + x where x is small (and positive).

Then $$r^n \approx 1 + n x + \frac{n^2 - n}{2} x^2 $$, Solve $$P (1 + n x + \frac{n^2 - n}{2} x^2) + m ((1 + n x + \frac{n^2 - n}{2} x^2) - 1)/x - B = 0$$ for x, but call it $$x_0$$, discard the negative term. (when won't this work? When might we want the negative term?)
$$x_0 = \frac{\sqrt{n^2 (m (n-1) -2 P)^2 - 8 n (n -1) P (P - B)}-n (m (n-1)+2 P)}{2 n (n-1) P} $$

Call this the first estimate.

Now if $$x_0$$ is "good" we can improve it via Newton's method on $$f(x) = P (1+x)^n + m ((1+x)^n - 1)/x - B$$
$$x_1 = x_0 - f(x_0)/f'(x_0) = x_0 + \frac{x_0 (1 + x_0) (m + B x_0 - (1 + x_0)^n (m + P x_0))}{m (1 + x_0) + (1 + x_0)^n (n P x_0^2 + m ((n-1) x_0 - 1))}
\\ x_2 = x_1 - f(x_1)/f'(x_1) \\ \dots $$

Test: I have 1 million dollars, and I can save USD 500 a month, every month for the next 20 years. What rate do I need to reach a goal of 2 million dollars?
$$P = 10^6, B = 2 \times 10^6, m = 500, n = 240 $$
$$x_0 = \frac{\sqrt{414106089}-12717}{2868000} \approx 37/13903 $$ (which is a little high)
$$x_1 = x_0 + \frac{x_0 (1 + x_0) (m + B x_0 - (1 + x_0)^n (m + P x_0))}{m (1 + x_0) + (1 + x_0)^n (n P x_0^2 + m ((n-1) x_0 - 1))} \approx 2/789 $$ which is better.
$$x_2 \approx 0.002532872 \approx 1077/425209$$ which gives an error of only about USD 0.21 over 20 years.
The true value of x is approximately 0.0025328716115386 or 4256833/1680635126 but cannot be expressed exactly with a finite number of digits, so learning to work with approximations is good.
 
Approximating $$r^n$$ by $$1 + n x$$ results in solving $$P (1 + n x ) + n m - B = 0$$ with solution $$x = \frac{B - (P + n m)}{n P}$$ which estimates $$r = 1 + \frac{B - (P + n m)}{n P}$$.
In the example above, this gives r = 3011/3000 which is too high as the excess balance is $$P r^n + m (r^n - 1)/(r - 1) - B \approx 598889.46$$.

Approximating $$r^n$$ by $$1 + n x + n (n-1) x^2 / 2 $$ results in solving $$P (1 + n x + n (n-1) x^2 / 2 ) + m (n + n (n-1) x / 2) - B = 0$$ with (positive) solution $$x = \frac{ -n (n-1) m - 2 n P \pm \sqrt{ n^2 ((n-1) m +2 P)^2 - 8 n (n-1) P (P + n m - B)) }}{2 (n-1) n P} = \frac{ -n (n-1) m - 2 n P \pm \sqrt{ n^2 ((n-1) m - 2P)^2 - 8 n (n-1) P (P - B) }}{2 (n-1) n P}$$ which estimates $$r = 1 + \frac{ -n (n-1) m - 2 n P + \sqrt{ n^2 ((n-1) m - 2P)^2 - 8 n (n-1) P (P - B) }}{2 (n-1) n P}$$.
In the example above, this gives $$r =(2855283 + \sqrt{414106089})/2868000$$ which is too high as the excess balance is $$P r^n + m (r^n - 1)/(r - 1) - B \approx
60100.37$$.

Approximating $$r^n$$ by $$1 + n x + n (n-1) x^2 / 2 + n (n-1) (n-2) x^3 / 6 $$ results in solving $$n (n-1) (n-2) P x^3 + (n (n-1)(n-2) m + 3 n (n-1) P) x^2 + (3 n (n-1) m + 6 n P) x + 6 (P + n m - B) = 0$$ with (ideally) one real, positive solution...
In the example above, this gives $$r = ( 710881 + \sqrt[3]{7364006553697261+178500 \sqrt{1783479138540197113797}}/\sqrt[3]{239^2} - 2214938521/\sqrt[3]{239 (7364006553697261+178500 \sqrt{1783479138540197113797}) } )/714000$$ which is too high as the excess balance is $$P r^n + m (r^n - 1)/(r - 1) - B \approx
7722.98$$

Approximating $$r^n$$ by $$1 + n x + n (n-1) x^2 / 2 + n (n-1) (n-2) x^3 / 6 + n (n-1) (n-2) (n-3) x^4 / 24$$ results in solving $$n (n-1) (n-2) (n-3) P x^4 + ( 4 n (n-1) (n-2) P + n (n-1) (n-2) (n-3) m ) x^3 + (12 n (n-1) P + 4 n (n-1) (n-2) m ) x^2 + ( 24 n P + 12 n (n-1) m ) x + 24( P + n m - B) = 0$$ with (ideally) one real, positive solution...
In the example above, this gives
$$r =
1
\\ -8237/1896000
\\ - \sqrt{-855081321/11882864000000 + \sqrt[3]{264511635799854916 + 3 \sqrt{13862403651956735545693529487553446}}/(84609000 \sqrt[3]{478^2}) - 48577848821/(84609000 \sqrt[3]{478 (264511635799854916 + 3 \sqrt{13862403651956735545693529487553446})})}/2
\\ + \sqrt{-855081321/5941432000000 - \sqrt[3]{264511635799854916 + 3 \sqrt{13862403651956735545693529487553446}}/(84609000 \sqrt[3]{478^2}) + 48577848821/(84609000 \sqrt[3]{478 (264511635799854916 + 3 \sqrt{13862403651956735545693529487553446})}) + 15042707035867373/(12115459179936000000000 \sqrt{-855081321/11882864000000 + \sqrt[3]{264511635799854916 + 3 \sqrt{13862403651956735545693529487553446}}/(84609000 \sqrt[3]{478^2}) - 48577848821/(84609000 \sqrt[3]{478 (264511635799854916 + 3 \sqrt{13862403651956735545693529487553446})})})}/2
\\ \approx 7071769852/7053889737
$$
which is too high as the excess balance is $$P r^n + m (r^n - 1)/(r - 1) - B \approx 883.57$$

Not only does the analytical approximation fail to converge quickly, but as mentioned before no analytical solution exists for higher degrees of polynomial approximation.

Thus numerical root polishing is required for high precision numerical solutions.
 
Last edited:
Thanks to Fednis and rpenner. I'll have to study those solutions to understand them.

In the meantime, I knocked out a little Excel function that does it iteratively. I know that r>=0 and probably <12. I also know that it will often be derived from an annual interest rate that will often be an integer (3%, 6%) or something with one or two decimal points (6.5%, 3.75%). So I had the UDF start with r=0 and increment it by 0.5% (annual rate) until it either got an exact match or was too high. If it was too high, I then had it divide the high and low by half until it found a match.

I am surprised by how well it works. I can post the actual code if anyone cares.

Thanks for all the help.
 
Solving $$B = P r^n + m \frac{r^n-1}{r-1}$$ for r when m is zero is much simpler:
$$r = \sqrt[n]{ \frac{B}{P} } = \left( \frac{B}{P} \right) ^ { \frac{1}{n} }$$.

Solving $$B = P r^n + m \frac{r^n-1}{r-1} $$ for r when P is zero proceeds as before but you can't just copy the method of above because the leading term is zero. So we need to use a quadratic equation in x to get a linear approximation.

Let r = 1 + x, and approximate $$r^n = 1 + n x + n (n-1) x^2 / 2 + n (n-1) (n-2) x^3/6$$.
Then we solve for x in $$B = m ( n + n (n-1) x / 2 + n (n-1) (n-2) x^2/6 ) = 0$$ or $$ (n-1) (n-2) x^2 + 3 (n-1) x + 6 - \frac{6 B}{m n} = 0$$ with a positive solution $$\frac{-3 (n - 1) + \sqrt{ 9 (n - 1)^2 - 4 (n - 2) (n - 1) (6 - \frac{6 B}{n m} ) } }{ 2 (n - 2) (n - 1) }$$
when $$ 0 < m < B/n $$ and $$3 \leq n $$.

Like the above method, this approximation is likely an overestimate because we are truncating the Taylor series for the power.
Thus for $$B= 10^6, m=500, n = 240$$ it gives $$x = \frac{-717 + \sqrt{10525321}}{113764} \approx 0.022215$$ while $$x \approx 0.01418199$$ is a much better answer.
 
Last edited:
You cant have exact equation for r. You can do it per iteration or cheat by using formula RATE in Excel :)
 
Back
Top