I have the following equation:
$$T=P\left [1+\sum_{i=1}^{n}(1.02)^i \right ]$$
How can I solve the equation for the $n$ value? I don't know how to expand the sum so I can handle algebraically $n$
I have the following equation:
$$T=P\left [1+\sum_{i=1}^{n}(1.02)^i \right ]$$
How can I solve the equation for the $n$ value? I don't know how to expand the sum so I can handle algebraically $n$
hint
if $a\ne 1$, then
$$a^p+a^{p+1}+a^{p+2}+...a^q=$$
$$a^p\frac {a^{q-p+1}-1}{a-1} .$$
in your case $$p=1 \;, \; a=1.02 \;,\;q=n $$
If $n $ is great , you can use the approximation
$$(1+0.02)^n\approx 1+0.02n $$
Making the problem more general, let us consider $$T=P\left [1+\sum_{i=1}^{n}a^i \right ]$$ and remember the geometric series $$\sum_{i=1}^{n}a^i =\frac{a \left(a^n-1\right)}{a-1}$$ Now, rearrange to isolate the term $a^n$ and get $$a^n=\frac{(a-1) T+P}{a P}$$ Now take logarithms of both sides to get $$n=\frac{\log\left(\frac{(a-1) T+P}{a P} \right) }{\log(a)}$$ which is the exact solution.
Now, if $a=1+\epsilon$ where $\epsilon\ll 1$ and, for conveniency, setting $T=\lambda P$ we have $$n=\frac{\log \left(\frac{1+\lambda \epsilon }{1+\epsilon}\right)}{\log (1+\epsilon )}$$ Using Taylor expansion around $\epsilon=0$, this would give $$n=(\lambda -1)-\frac{1}{2} \lambda\left(\lambda -1\right) \epsilon +\frac{1}{12} \left(4 \lambda ^3-3 \lambda ^2-\lambda \right) \epsilon ^2+O\left(\epsilon ^3\right)$$ For illustration purposes, let us consider $\lambda=10$ (that is to say $T=10P$) and $\epsilon=0.02$; the above approximation would give $n=8.22300$ while the exact value should be $n=8.20694$
Edit
If you want to avoid logarithms and Taylor series, you could use instead Padé approximants. The simplest would give $$n=\frac{(\lambda -1) ((1+\lambda) \epsilon +6)}{(4 \lambda+1) \epsilon +6}$$ which, for the worked example, would give $n=\frac{2799}{341}\approx 8.20821$.
Let $r=0.02$.
$$\begin{align} T&+P\bigg[1+\sum_{i=1}^n (1+r)^i\bigg]\\ &=P\sum_{i=0}^n (1+r)^i\\ &=P\cdot \frac {(1+r)^{n+1}-1}{(1+r)-1}\\ &=\frac Pr\left((1+r)^{n+1}-1\right)\\ 1-\frac {rT}P&=(1+r)^{n+1}\\ n&=\color{red}{\frac {\log(1-\frac {rT}P)}{\log(1+r)}-1} \end{align}$$
Note that a real solution for $n$ exists only if $\frac {rT}P>1$, ie. $r>\frac PT$.
Also, $n$ must be rounded up to the nearest integer (as it must be an integer) meaning that the sum may not be exact, but the number of periods for repayment (assuming this is a time value of money problem, which it appears to be) should be correct.