sequence that adds its previous results

45 Views Asked by At

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.

3

There are 3 best solutions below

0
On

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$

0
On

Your sequence seems to be $a_n = x + x^2 + x^3 + ..... + x^n$

$= (1 + x + x^2 + x^3 + ...... + x^n) - 1$

$= \frac {1-x^{n+1}}{1-x}-1$

$=\frac {1-.3^{n+1}}{.7} - 1$

Google geometric series

Or maybe more straightforward:

$a_n = x + x^2 + ...... + x^n =$

$x(1 + ..... + x^{n-1}) =$

$x \frac {1-x^n}{1-x} = \frac {x - x^{n+1}}{1-x}=$

$\frac {.3-.3^{n+1}}{.7}$

Which can be what $\frac {1 - .3^{n+1}}{.7} -1 = \frac {1 - .3^{n+1}}{.7} -\frac {.7}{.7} = \frac {.3-.3^{n+1}}{.7}$ is also equal to.

You can also express it as $\frac {3 - 10*(.3)^{n+1}}{7}$

0
On

If we write $$a_n=1+0.3+(0.3)^2+\cdots + (0.3)^{n-2}$$then we have $$a_{n+1}=a_n+(0.3)^{n-1}=1+0.3+(0.3)^2+\cdots + (0.3)^{n-2}+(0.3)^{n-1}$$also $$1+0.3+(0.3)^2+\cdots + (0.3)^{n-2}={1-(0.3)^{n-1}\over 1-0.3}$$therefore $$a_n={1-(0.3)^{n-1}\over 0.7}$$