Generating Function & Sequence

generating-functionssequences-and-series

Find the generating functions of the sequences
2, 1, 2, 1, 2, 1, . . .

I get $\frac{1}{1+x} + \frac{1}{1-x} = \frac{2}{1-x^2}$

But the solution ends up with $\frac{2}{1-x^2} + \frac{x}{1-x^2} = \frac{2+x}{1-x^2}$.
The solutions starts with $\sum_{n\ge 0} (2)x^{2n}+\sum_{n\ge 0} (1) x^{2n+1}$

I couldn't come up with anything like that. I feel like I'm confused with something.

Best Answer

The sequence $2,1,2,1,2,1,...$ alternates between $2$ and $1$, being $2$ for even-numbered terms and $1$ for odd-numbered terms. The generating function is thus $$\sum\limits_{n \ge0}(2)x^{2n}+\sum\limits_{n\ge0}(1)x^{2n+1}=\sum\limits_{k\ge0}(1)x^k+\sum\limits_{k\ge0}(1)x^{2k}=\dfrac{1}{1-x}+\dfrac{1}{1-x^2}=\dfrac{2+x}{1-x^2}$$

Related Question