I have the following equation:$$a_n = n((-1)^n(1-n) + 3^{n-1})$$
How do I convert this into a closed form of the generating function?
I have the following equation:$$a_n = n((-1)^n(1-n) + 3^{n-1})$$
How do I convert this into a closed form of the generating function?
Hint(s): This splits up into three terms: $(-1)^nn$, $-(-1)^nn^2$, and $3^{n-1}n$.
The first gives the series $\sum (-1)^n nx^n$; the easiest way to figure out the generating function is to write \begin{equation*} \sum_{n=1}^\infty (-1)^n nx^n = \sum_{n=1}^\infty (-1)^n (n-1)x^n + \sum_{n=1}^\infty (-1)^n x^n. \end{equation*} The second term is pretty easy from what you know: \begin{equation*} \sum_{n=1}^\infty (-1)^n x^n = \sum_{n=1}^\infty (-x)^n = -x\sum_{n=1}^\infty (-x)^{n-1} = -x\sum_{n=0}^\infty (-x)^n = -\frac{x}{1+x}. \end{equation*} For the first term, write $f(x) = \sum_{n=1}^\infty (-1)^n (n-1)x^n$, then integrate both sides. This should give you an expression for $\int f(x)\,dx$ that you can turn into a closed form function given what you know; differentiate it to get $f(x)$.
Next, $\sum_{n=1}^\infty 3^{n-1}nx^n = \frac{1}{3}\sum_{n=1}^\infty n(3x)^n$. Apply the same technique here as we just did for $\sum (-1)^nn x^n$.
Finally, the third series is $-\sum_{n=1}^\infty (-1)^n n^2x^n$. This is a little harder if you haven't seen it before. One way is as follows. Let $S$ represent the sum. Then \begin{align*} S &= -\sum_{n=1}^\infty (-1)^n n^2x^n = -\sum_{n=0}^\infty (-1)^{n+1}(n+1)^2x^{n+1} \\ &= \sum_{n=0}^\infty (-1)^nn^2x^{n+1} + 2\sum_{n=0}^\infty (-1)^nnx^{n+1} + \sum_{n=0}^\infty (-1)^n x^{n+1} \\ &= -xS + 2x\sum_{n=0}^\infty (-1)^nn x^n + x\sum_{n=0}^\infty (-1)^nx^n. \end{align*} From what you know, and the calculations above, you should be able to solve for $x$ in closed form.