Find the formula of the sequence using generating functions I have the following sequence given:
$$\sum_{k=1}^{n} (-1)^{k}k^{2}$$
How can I do this? The sequence goes like this:
$$-1 + 4 - 9 + 16 - 25 + 36 - ...$$
So it doesn't have any variables inside. It looks like a geometric sequence for me, so the simple known formula would do the whole thing, but I actually doubt it's that simple.
So there are some generating functions that are quite similar, like:
$$\sum (-1)^{n}x^{n} = x - x^{2} + x^{3} - x^{4} + ...$$
But, uhm, well...what's next? The lack of x variable seems a bit strange to me.

The generating function is
$$
\begin{align}
\sum_{n=0}^\infty\sum_{k=0}^n(-1)^kk^2x^n
&=\sum_{k=0}^\infty\sum_{n=k}^\infty(-1)^kk^2x^n\\
&=\sum_{k=0}^\infty(-1)^kk^2\frac{x^k}{1-x}\\
&=\frac1{1-x}\sum_{k=0}^\infty(-1)^kk^2x^k\tag{1}
\end{align}
$$
Starting with $\frac1{1+x}$ and taking derivatives, we get
$$
\begin{align}
\frac1{1+x}&=\sum_{k=0}^\infty(-1)^kx^k\\
\frac1{(1+x)^2}&=\sum_{k=0}^\infty(-1)^k(k+1)x^k\\
\frac2{(1+x)^3}&=\sum_{k=0}^\infty(-1)^k(k+2)(k+1)x^k
\end{align}\tag{2}
$$
Since $k^2=(k+2)(k+1)-3(k+1)+1$, we have
$$
\begin{align}
\sum_{k=0}^\infty(-1)^kk^2x^k
&=\frac2{(1+x)^3}-\frac3{(1+x)^2}+\frac1{1+x}\\
&=\frac{(x-1)x}{(1+x)^3}\tag{3}
\end{align}
$$
Thus, the generating function we want is
$$
\begin{align}
\frac1{1-x}\sum_{k=0}^\infty(-1)^kk^2x^k
&=\frac1{1-x}\frac{(x-1)x}{(1+x)^3}\\
&=-\frac{x}{(1+x)^3}\\
&=-\sum_{n=0}^\infty\binom{-3}{n-1}x^n\\
&=\sum_{n=0}^\infty(-1)^n\binom{n+1}{n-1}x^n\\
&=\sum_{n=0}^\infty(-1)^n\binom{n+1}{2}x^n\tag{4}
\end{align}
$$
Therefore,
$$
\sum_{k=0}^n(-1)^kk^2=(-1)^n\binom{n+1}{2}\tag{5}
$$
