Assignment problem 2. Calculate the expected value and variance of the binomial distribution using the moment generating function.

The binomial PMF is defined as

\[(^n_x)p^xq^{n - x}\]

so the moment generating function is:

\[M(t) = \sum_{x=0}^n e^{tx}(^n_x)p^xq^{n-x} = \sum_{x=0}^n(^n_x)(pe^t)^xq^{n-x}=(pe^t+q)^n\]

\[M'(t)=n(pe^t+q)^n-1pe^t\] \[E(X)=M'(0)=np\]

\[M''(t)=n[1-p+pe^t]^{n-1}(pe^t)+(pe^t)n(n-1)[1-p+pe^t]^{n-2}(pe^t)\]

\[E(X^2) = M''(0)=n(n-1)p^2+np\]

\[Var(X)=E(X^2) - E(X)^2 = n(n-1)p^2+np-(np)^2\]

\[=(n^2p^2-1np^2)+np-(np)^2\]

\[=(np)^2-np^2+np-(np)^2\]

\[=np-np^2=np(1-p)\]