$f \colon \mathbb{R} \rightarrow \mathbb{R}$, $f$ is continuous , and $f(x+1)+f(x)=x^2$ I would appreciate if somebody could help me with the following problem:

Find $f(x)$ ($f(x)$ is not Polynomial function), given that:
$f \colon \mathbb{R} \rightarrow  \mathbb{R}$, $f$ is continuous, and $f(x+1)+f(x)=x^2$

I tried  but couldn't get it that way.
 A: Let $f(x)=\frac{x^2-x}{2}+\sin(\pi x)$. Then, $f(x+1)+f(x)=\frac{x^2+2x+1-(x+1)}{2}+\sin(\pi x + \pi)+\frac{x^2-x}{2}+\sin(\pi x)=x^2$.
As $\frac{x^2-x}{2}$ can be found easily, $sin(\pi x)$ can be replaced by any other non-polynomial continuous function $g$ with $g(x+1)+g(x)=0$.
A: It might be helpful to first find $f:\Bbb N \to \Bbb R$, then extend the result.
We can solve the recurrence relation $f(n) + f(n+1) = n^2$ via generating functions: define $F(x) = \sum_{n=0}^\infty f(n) x^n$.  Then
$$
f(n) + f(n+1) = n^2\\
\sum_{n=0}^\infty [f(n) + f(n+1)]x^n = \sum_{n=0}^\infty n^2 x^n \\
\sum_{n=0}^\infty f(n)x^n +
\sum_{n=0}^\infty f(n+1)x^n = 
\sum_{n=0}^\infty n^2 x^n\\ 
\sum_{n=0}^\infty f(n)x^n +
\sum_{n=1}^\infty f(n)x^{n-1} = 
\sum_{n=0}^\infty n^2 x^n\\ 
F(x) + 
\frac 1x \left(F(x) - f(0)\right) = 
\frac{x(x+1)}{(x-1)^3}\\
xF(x) + 
F(x) - f(0) = 
\frac{x^2(x+1)}{(x-1)^3}\\
(x+1)F(x) = 
\frac{x^2(x+1)}{(x-1)^3} + f(0)\\
F(x) = 
\frac{x^2}{(x-1)^3} + \frac{f(0)}{x+1}\\
\sum_{n=0}^\infty f(n) x^n = 
\sum_{n=0}^\infty \frac{n(n+1)}{2} x^n + 
f(0)\sum_{n=0}^\infty (-1)^n x^n
$$
So setting $f(0) = a$ for any $a$, we find
$$
f(n) = \frac{n(n+1)}{2} + a(-1)^n = 
\frac{n(n+1)}{2} + a\cos(\pi n)
$$
if a solution to the problem over $\Bbb R$ exists, it must be an extension of this function for some value of $a$.
In fact, $f(x) = \frac{x(x+1)}{2} + a\cos(\pi x)$ seems to work for any $a \in \Bbb R$.

A more general solution (taken from Salomo's work) is
$$
f(x) = \frac{x(x+1)}{2} + g(x)
$$
where $g(x)$ satisfies $g(x+1) + g(x) = 0$.
A: Let's first consider the function on $\mathbb{Z}$.
$$
\begin{align}
\sum_{k=0}^{n-1}(-1)^k(f(k+1)+f(k))
&=\sum_{k=1}^n(-1)^{k-1}f(k)+\sum_{k=0}^{n-1}(-1)^kf(k)\\
&=(-1)^{n-1}f(n)+f(0)\tag{1}
\end{align}
$$
Furthermore,
$$
\begin{align}
\sum_{k=0}^{n-1}(-1)^kk^2\tag{2}
&=(-1)^{n-1}\frac{n(n-1)}2
\end{align}
$$
Combining $(1)$ and $(2)$ yields
$$
f(n)=\frac{n(n-1)}2+(-1)^nf(0)\tag{3}
$$
If we set $f(0)=0$, we get
$$
\bbox[5px,border:2px solid #FFC000]{f(x)=\frac{x(x-1)}2}\tag{4}
$$
Checking, we get
$$
f(x+1)+f(x)=x^2\tag{5}
$$
This gives us one solution. Suppose we have two solutions, $f$ and $g$. Then
$$
(f-g)(x+1)+(f-g)(x)=0\tag{6}
$$
That is, $(f-g)(x+1)=-(f-g)(x)$. Thus, the general solution is
$$
\bbox[5px,border:2px solid #FFC000]{f(x)=\frac{x(x-1)}2+h(x)}\tag{7}
$$
where $h$ is any continuous function where $h(x+1)=-h(x)$.
An example of such an $h(x)$ would be $a\cos(\pi x)+b\sin(\pi x)$.
A: Let $f$ be a solution of the equation $f(x+1)+f(x)=x^2$. Consider $h(x)=f(x) - \frac{x(x-1)}{2}$, i.e. $f(x)=h(x) + \frac{x(x-1)}{2}$. Then the equation simply becomes:
$$h(x+1) + h(x) = 0$$
It is clear that such a function $h$ is completely determined by what it does on $[0,1[$, where $h$ can be defined arbitrarily. Conversely, every $h$ gives a solution $f$. Finally, $f : \mathbb{R} \to \mathbb{R}$ is continuous if and only if $h : \mathbb{R} \to \mathbb{R}$ is continuous.
