find expectation of non-negative integer valued RV from generating function How can we find $E\left(X\right)$ and $E\left(X^{2}\right)$ if all
we have is that $G\left(s\right)$ is the generating function for
X, which takes non-negative integer values.

I know $E\left(X\right)$ = $G'\left(1\right)$ and $G\left(s\right)=$$\sum_{i=0}^{\infty}s^{i}P\left(X=i\right)=\sum_{i=0}^{\infty}s^{i}f(i)$
but how can I take the derivative?
$E\left(X\right)$ = $G'\left(1\right)$ and $G\left(s\right)=$$\sum_{i=0}^{\infty}s^{i}P\left(X=i\right)=\sum_{i=0}^{\infty}s^{i}f(i)$

$G'(s) = \sum_{i=0}^{\infty}is^{i-1}f\left(i\right)$ 

$G''(s) = \sum_{i=0}^{\infty}i\left(i-1\right)s^{i-2}f\left(i\right)$ 

$G''(1) = \mathrm{E}(X^{2}) - \mathrm{E}(X)$

Just take the derivative with respect to s and you can play with my expression for $G''(s)$ (by splitting it into two summations) if you want to see the algebra.
$G''(1)=E(x^2)-E(x)$
then $E(x^2)=G''(1)+G'(1)$