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?


The derivative of $f(x)$ is equal to $\dfrac{(a-1)(x^2-1)}{(x^2+x+1)^2}$ so the extremes are independent of a and taken at $x=\pm 1$. This extremes are $\dfrac{2\pm a}{3}$ It follows $0\le a\le 2$