So I was reading the random walk article from wiki, and was currently focusing on the Lattice Random Walk section: There, I understand the definition of $Z_1,Z_2...Z_n$, which defines $Z_i$ as a random variable taking values $1$ or $-1$ with $50\%$ probability.
Then a random walk is defined as a series $S_n = \sum_{j=1}^{n}Z_j$. Then we find the expectation of the random walk is $E(S_n) = \sum_{j=1}^{n}E(Z_j) = 0$. It then says that $E(Z_n^2) = 1$, which is probably okay, if $Z_n^2 = 1$, which is the case. But then it comes up saying, $E(S_n^2) = \sum_{i=1}^n\sum_{j=1}^nE(Z_jZ_i) = n$, and I don't get how this came to be.
First of all what is $S_n^2$? Is it $S_n^2 = (\sum_{j=1}^n Z_j)(\sum_{j=1}^n Z_j)$ If this is so, I am not sure how to calculate the expectation of the previous expression?
Thanks for the help.
The random variable $S_n^2$ is just the product of the random variable $S_n$ with itself. In order to write $S_n^2$ in terms of the $Z_j$'s, we can multiply out the two products to get $$ S_n^2 = \left( \sum_{i=1}^n Z_i \right)\left( \sum_{j=1}^n Z_j \right) = Z_1 \left( \sum_{j=1}^n Z_j \right) + \ldots + Z_n \left( \sum_{j=1}^n Z_j \right) = \sum_{i=1}^n \sum_{j=1}^n Z_i Z_j . $$ Using the linearity of the expectation, we find that $$ E[S_n^2] = \sum_{i=1}^n \sum_{j=1}^n E[Z_i Z_j] = \sum_{i=1}^n 1 = n, $$ where the last equality follows since $E[Z_i^2] = 1$ and $E[Z_i Z_j ] = 0$ for $i \not= j$.