Let $x = 0.3$. The first number of the sequence is $x$. The second number is the first number + $(0.3\cdot 0.3)$. The third number is the second number + $(0.3\cdot 0.3\cdot 0.3)$.
This is a recursive formula:
$a_1 = 0.3$
$a_{n+1} = a_n + 0.3^{n-1}$
Is it possible to write this equation without recursion?
I want to write a programming function in JavaScript that encodes this without using recursion if possible.
You can write:
$a_{n+1} = a_n + 0.3^{n-1}$
$= a_{n-1} + 0.3^{n-2} + 0.3^{n-1}$
$ = a_{n-2} + 0.3^{n-3} + 0.3^{n-2} + 0.3^{n-1}$
$ ... $
$ = a_1 + \sum_{k=1}^n 0.3^{n-k+1}$
$ = a_1 + \sum_{k=1}^n 0.3^k$
$ = a_1 + \frac{3}{7}(1-0.3^n)$
$ = 0.3 + \frac{3}{7}(1-0.3^n)$
$ = 0.7286 - 0.4286 \times 0.3^n$