<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] Rewrite
$$f(x) = 1 + \frac{(a-1)x}{x^2+x+1}$$
and note that $f(x) \in [0,2]$ is equivalent to $(a-1)\frac{x}{x^2+x+1} \in [-1,1]$.
Notice that $\frac{x}{x^2+x+1} \in [-1,1]$:
$$\frac{x}{x^2+x+1} \le 1 \iff 0 \le x^2+1$$
$$\frac{x}{x^2+x+1} \ge -1 \iff 0 \le x^2+2x + 1$$
Now, if $a \in [0,2]$ then $|a-1| \le 1$ so
$$|a-1|\underbrace{\left|\frac{x}{x^2+x+1}\right|}_{\le 1} \le 1, \forall x \in \mathbb{R}$$
Conversely, if $(a-1)\frac{x}{x^2+x+1} \in [-1,1], \forall x \in \mathbb{R}$ then in particular for $x = -1$ we get $1-a \in [-1,1]$ which implies $a \in [0,2]$.
We conclude $f(x) \in [0,2], \forall x \in \mathbb{R}$ if and only if $a \in [0,2]$.
</s>