This is a general finite case of the infinite sequence evaluated in the solution to Many Heads: 1/2 + 2/4 + 3/8 + 4/16 + ..., where x is 1/2 and n infinite.
Let y = x + 2x + 3x^3 + ... + nx^n
Dividing by x,
y/x = 1 + 2x + 3x^2 + ... + nx^(n1)
Subtracting,
y/x  y = 1 + x + x^2 + ... + x^(n1)  nx^n
Multiplying by x,
y  xy = x + x^2 + x^3 + x^4 + ... + x^n  nx^(n+1)
Subtracting,
y/x  2y + xy = 1  (n+1)x^n + nx^(n+1)
y(x  2 + 1/x) = 1  (n+1)x^n + nx^(n+1)
y = (1  (n+1)x^n + nx^(n+1)) / (x  2 + 1/x)
This can be verified with various x and n using the following program:
INPUT "x and n:", x, n
term = x: t = term
FOR termNo = 2 TO n
term = term * x
t = t + termNo * term
NEXT termNo
PRINT t
PRINT (1  (n + 1) * x ^ n + n * x ^ (n + 1)) / (x  2 + 1 / x)
Also, when x is equated to 1/2 and n allowed to increase without limit, the limiting value of the formula is indeed 2 as in the solution to Many Heads.
Edited on December 14, 2004, 6:39 pm

Posted by Charlie
on 20041214 18:08:42 