<s>[INST] Find $a\in\mathbb{R}$ such that the image of $f(x)=\frac {x^2+ax+1}{x^2+x+1}$ is included in $[0,2]$. 
Find $a\in\mathbb{R}$ such that the image of $f(x)=\frac {x^2+ax+1}{x^2+x+1}$ is included in $[0,2]$.

My attempt:
We have: $f'(x)=-\frac{(a-1)(x^2-1)}{(x^2+x+1)^2}\implies x = 1$ and $x = -1$ points of extrema.
then for $a\geq 1$:

so then $$2-a=0\implies a=2$$ and $$\frac {a+2}3=2\implies a=4.$$
and for $a\leq1:$

so then $$2-a=3\implies a=-1$$ and $$\frac {a+2}3=0\implies a=-2.$$
Now my answers are in the type of interval. How do I know which interval to choose?
 [/INST] You're doing well. The derivative is
$$
f'(x)=-\frac{(a-1)(x^2-1)}{(x^2+x+1)^2}=(1-a)\frac{(x^2-1)}{(x^2+x+1)^2}
$$
Leaving aside $1-a$, the fraction is negative for $|x|<1$.
If $1-a>0$, the function has a maximum at $-1$ and a minimum at $1$. The situation is reversed for $1-a<0$. For $a=1$ the function is constant and satisfies the requirement.
Since $\lim_{x\to\pm\infty}f(x)=1$, we just need to compute
$$
f(-1)=2-a
\qquad
f(1)=\frac{2+a}{3}
$$
Thus we must have
$$
\begin{cases}
1-a>0 \\[4px]
2-a\le2 \\[4px]
2+a\ge0
\end{cases}
\qquad\text{or}\qquad
\begin{cases}
1-a<0 \\[4px]
2-a\ge0 \\[4px]
2+a\le6
\end{cases}
\qquad\text{or}\qquad a=1
$$
Solving this gives $0\le a\le 2$.
</s>