I want to derive the result that for a geometric distribution $$X \sim Geo(p)$$ The expected value is equal to $$E(x)=\frac{1}{p}$$
I have started off by using the definition of $E(x)$ being the mean
$$E(x)=\sum xP_x$$
And we can write $\sum xP_x$ as
$$\sum xP_x= p + 2qp + 3q^2p + 4q^3p......+ nq^{n-1}p $$
Multiplying $\sum xP_x$ by $q$ and then taking the difference of the two expressions
$$\left[\sum xP_x= p + 2qp + 3q^2p + 4q^3p......+ nq^{n-1}p \right] $$
$$-\left[ q\sum xP_x= qp + 2q^2p + 3q^3p + 4q^4p......+ (n-1)q^{n-1}p + nq^np \right]$$ $$\text{_________________________________________________________________}$$ $$\sum xP_x \left(1-q \right)=p+qp+q^2p.....+q^{n-1}p +nq^np$$ $$\text{_________________________________________________________________}$$
From here we can see that the right hand side excluding the last term forms the sum of a geometric progression hence we can use the formula for the sum of first $n$ terms of a geometric progression which is in this case $$\frac{p(1-q^n)}{1-q}$$ $$\because p=1-q$$ $$\therefore \frac{p(1-q^n)}{1-q} \iff 1-q^n$$
Now the expression simplifies to $$\sum xP_x \left(1-q \right)= 1-q^n + nq^np$$ $$\sum xP_x \left(1-q \right)= 1-q^n + nq^n(1-q)$$ $$\sum xP_x \left(1-q \right)= 1-q^n + nq^n - nq^{n+1}$$
At this point it is apparent I have made a mistake somewhere as even by simplifying it further
$$\sum xP_x \left(1-q \right)= 1-q^n(1 + n - nq)$$ $$\sum xP_x \left(1-q \right)= 1-q^n(1 + n(1 - q))$$ $$\sum xP_x = \frac{1-q^n(1 + np)}{\left(1-q \right)}$$
And I have no clue on how to proceed, where have I messed up or have I taken a wrong method entirely?
there is a very simple way to do that:
$$\mathbb{E}[X]=\sum_{x=1}^{\infty}xpq^{x-1}=p\sum_{x=1}^{\infty}xq^{x-1}=$$
$$=p\sum_{x=1}^{\infty}\frac{d}{dq}q^x=p\frac{d}{dq}\sum_{x=1}^{\infty}q^x=$$
$$=p\frac{d}{dq}\frac{q}{1-q}=p\frac{1}{(1-q)^2}=\frac{1}{p}$$
Doing in your manner you get
$$\mathbb{E}[X]=p+2pq+3pq^2+4pq^3+\dots=p[1+2q+3q^2+4q^3+\dots]=pS$$
Now let's focus on the sum S
$$S=1+2q+3q^2+4q^3+\dots$$
$$Sq=q+2q^2+3q^3+4q^4+\dots$$
Subtracting member to member you get
$$S(1-q)=1+q+q^2+q^3+\dots$$
remembering the sum of a geometric series you immediately get
$$S(1-q)=\frac{1}{1-q}$$
thus
$$\mathbb{E}[X]=pS=\frac{p}{(1-q)^2}=\frac{1}{p}$$