I've got quiet a strange problem but a simple one I guess. So I have a starting sum of 10 and I would like to know how many years need to pass to achieve 30000 with 32% interest applied every 2 years. There's an equation for such problems:
K = Ko (1 + p / (100*m) )^(m*n)
where K is the target sum, Ko is the starting sum, p is the percent, m is how many times an interest is applied in a year and n is years. I took K = 30000, Ko = 10, p = 32, m = 1/2, n - the unknown. Following this pattern I got to such equation:
n = log_(sqrt(1,64)) (30000 / 10) = 32,36...
based sqrt(1,64) logarithm of (30000/10)
Secondly to check the correctness of this equation I've written a simple program in C++:
#include <stdio.h>
#include <conio.h>
int main()
{
int total = 30000;
int current = 10;
int n = 0;
while(current < total)
{
current = current * 1.32;
n+=2;
}
printf("%d", n);
_getch();
}
which gives me n = 60. I know this program is inaccurate and won't give a precise result but such difference between results proves that one solution must be wrong? The program is very simple and it seems to me correct so I guess that the mathematical formula above doesn't work in my case?
Two problems.
Problem 1. You quote a formula
K = Ko (1 + p / (100*m) )^(m*n)But the formula you're trying to implement should have(1 + p / 100)rather than(1 + p / (100*m)).$$\begin{align} K &= K_0 ( 1+ p/100)^{mn} \\ \log\frac{K}{K_0} &= mn \log(1+p/100) \\ n &= \frac{1}{m}\frac{\log(K/K_0)}{\log(1+p/100)} \\ &= 2\frac{\log(30000/10)}{\log(1.32)} \end{align} $$
Evaluating
2*log(30000/10)/log(1.32)gives57.67617, i.e. 58 rounded up to the nearest two years.Problem 2. You use
intin your program when you should usedouble. Once you correct your program, as below, you get 58 not 60 out of your program.(ideone online program)