Solving equation $a_n=1+\frac12a_{n-1}+\frac12a_{n+1}$ Let's consider sequence following for $n=0...,T$ for which $a_0=a_T=0$. I want to solve equation $$a_n=1+\frac12a_{n+1}+\frac12a_{n-1}$$
My work so far
$$a_1=1+\frac12a_2 \Leftrightarrow a_2=2a_1-2$$
$$a_2=1+\frac12a_3+\frac12a_1 \Leftrightarrow2a_1-2=1+\frac12a_3 \Leftrightarrow a_3=3a_1-6$$
Also I calculated $a_4$ to get $a_4=4a_1-12$. So my observation is that for any $n \in \{1,...,T-1\}$
we have $$a_n=na_1+n(n-1)$$
And here I stacked, I'm not sure what to do next. Could you please give me a hand solving this equation ?
 A: Hint 1: Prove by induction that your guess is correct.
Hint 2  If $a_T=0$ then
$$Ta_1+T(T-1)=0$$
Use this to find $a_1$.
A: $$a_{n+1} - a_n -(a_n-a_{n-1}) = -2 \implies a_n - a_{n-1} = (a_1-a_0) - 2(n-1).$$
Can you take it from here?

 Next $$a_n-a_0=\sum_{k=1}^n(a_k-a_{k-1}) = n(a_1-a_0) - 2\sum_{k=1}^n(k-1).$$

Lastly, plug in $n=T$ and solve for $a_1$.
A: Consider the generating function $$f(x)=\sum_{n\ge0}a_nx^n,\qquad|x|<1.$$
We may write
$$2a_{n+1}x^{n+2}=2x^{n+2}+a_{n+2}x^{n+2}+a_{n}x^{n+2},$$
and sum over $n\ge 0$:
$$2x\sum_{n\ge0}a_{n+1}x^{n+1}=2x^2\sum_{n\ge0}x^n+\sum_{n\ge0}a_{n+2}x^{n+2}+x^2\sum_{n\ge0}a_nx^n,$$
which is
$$2x(f(x)-a_0)=\frac{2x^2}{1-x}+f(x)-a_0-a_1x+x^2f(x).$$
Using $a_0=0$, and treating $a_1$ as a constant,
$$(x^2-2x+1)f(x)=\frac{(a_1+2)x^2-a_1x}{x-1},$$
so that
$$f(x)=\frac{(a_1+2)x^2-a_1x}{(x-1)^3}.$$
Then let the sequences $p_n$ and $q_n$ be defined by
$$\begin{align}
p(x)=\frac{x^2}{(x-1)^3}&=\sum_{n\ge0}p_nx^n\\
q(x)=\frac{x}{(x-1)^3}&=\sum_{n\ge0}q_nx^n,
\end{align}$$
so that
$$f(x)=(a_1+2)p(x)-a_1q(x)=\sum_{n\ge0}((a_1+2)p_n-a_1q_n)x^n,$$
giving $a_n=(a_1+2)p_n-a_1q_n$.
Differentiating the series $\frac{1}{1-x}=\sum_{n\ge0}x^n$ three times gives
$$\frac{1}{(x-1)^3}=\sum_{n\ge0}x^n\left(-\frac{1}{2}(n+1)(n+2)\right),$$
so that
$$\begin{align}
p(x)=\frac{x^2}{(x-1)^3}&=\sum_{n\ge0}x^n\left(-\frac{1}{2}n(n-1)\right)\quad &\Rightarrow p_n=-\frac12n(n-1)\\
q(x)=\frac{x}{(x-1)^3}&=\sum_{n\ge0}x^n\left(-\frac{1}{2}n(n+1)\right)\quad &\Rightarrow q_n=-\frac12n(n+1).
\end{align}$$
Therefore
$$a_n=(a_1+2)p_n-a_1q_n=n(a_1+1-n).$$
To find $a_1$, we use $a_T=0$. Specifically we have
$$T(a_1+1-T)=0\Rightarrow a_1=T-1.$$

Thus we have $$a_n=n(T-n).$$

