Find all real values of $m$ such that all the roots of $f(x)=x^3-(m+2)x^2+(m^2+1)x-1$ are real I have the following polynomial with real coefficients:
$$f(x)=x^3-(m+2)x^2+(m^2+1)x-1$$
I have to find all real $m$'s so that all of the roots of $f$ are real.
Trying to guess a root didn't get me anywhere.
I computed $x_1^2+x_2^2+x_3^2$ using Vieta's relations to be $-(m-2)^2+6$. This has to be positive if the roots are real, so $m\in[-\sqrt6+2, \sqrt6+2]$.
I tried using the derivative of $f$ and Rolle's theorem, but the calculations get complicated quite fast. I managed to prove that m has to be somewhere in the interval $(-\sqrt\frac32+1, \sqrt\frac32+1)$, though I can't guarantee that this is correct. I could continue this way and I'll probably reach a solution sooner or later, but I hope there's a much more elegant solution that I've missed.
Thanks for your help!
 A: I shall assume that we want three different real roots
Consider $$f(x)=x^3-(m+2)x^2+(m^2+1)x-1$$ The first condition is that
$$f'(x)=3x^2-2(m+2)x+(m^2+1)$$ shows two real roots which are
$$x_\pm=\frac{1}{3} \left(m+2\pm\sqrt{-2 m^2+4 m+1}\right)$$ This gives the first condition
$$-2 m^2+4 m+1 > 0$$
Now, you need that
$$f(x_-) \times f(x_+) <0$$ that is to say
$$3 m^6-4 m^5+6 m^4-22 m^3-9 m^2+26 m+23 < 0$$ which cannot be solved. Numerical calculations give
$$1.558 < m < 1.756 $$
A: hint
$f$ satisfies Rolle's Theorem, so if it has three roots, its derivative will have two real roots, $\color{red}{a,b}.$
$$f'(x)=3x^2-2(m+2)x+m^2+1$$
the reduced discriminant $$\delta=(m+2)^2-3(m^2+1)$$
$$=-2m^2+4m+1$$
should necessarily be $>0$.
To be sufficient, you need
$$f(a)f(b)<0$$
A: This answer should be seen as a complement to the other answers.
A third degree curve $y=f(x)=x^3+\cdots$ is known to have two possible shapes

according to the fact that its derivative has sign changes (necessarily a "$+ - +$" pattern) or not (a simple "+" pattern), i.e., respectively two real roots $a,b$ or no real root. [we leave apart the limit case of one real root]. In the first case, we have a relative maximum in $(a,f(a))$, followed by a relative minimum in $(b,f(b))$. There will be 3 real roots if $(a,f(a))$ is above $x$ axis and $(b,f(b))$ is below $x$ axis ; this is equivalent to say that
$$f(a)f(b)<0$$
This condition has to be expressed in terms of parameter $m$.
I will use for that a method that is classical, but necessitates to know what a resultant is (explanations below). It suffices to write twice the coefficients of $f$, ans 3 times the coefficients of $f'$, with a shift for the first one and two shifts for the second one
$$Res(f,f')=\begin{vmatrix} 1&   - m - 2&   m^2 + 1&        -1&       0\\
0&         1&   - m - 2&   m^2 + 1&      -1\\
 3& - 2m - 4&   m^2 + 1&         0&       0\\
0&         3& - 2m - 4&   m^2 + 1&       0\\
0&         0&         3& - 2m - 4& m^2 + 1\end{vmatrix}=0\tag{2}$$
which is identical to
$$3m^6 - 4m^5 + 6m^4 - 22m^3 - 9m^2 + 26m + 23=0$$
(the very same polynomial found by Claude).
Explanation about the calculation : the nullity of the resultant $Res(f,g)=0$ of 2 (parametric) polynomials $f$ and $g$ is a necessary and sufficient condition for these polynomials to have a common root ; here in the case $g=f'$ ; $f$ and $f'$ have a common root if and only $f$ has a double root. It is known to be a limit case between cases "a single real root" and "3 real roots". The sign of this resultant will change once we have crossed the case $R(f,f')=0$.
The resultant $R(f,g)$ can be computed in (at least) two ways :

*

*up to a factor, it is the the product of values of $f$ computed at the roots of $g$, which is formula (1)


*as the determinant computed above (in (2)) .
Remark : $Res(f,f')$ is called the discriminant of $f$ : it generalizes the discriminant of a a second degree polynomial $ax^2+bx+c$ for which the corresponding resultant is :
$$\begin{vmatrix}  a&   b& c\\
 2a&   b& 0\\
0& 2a& b\end{vmatrix}=-a(b^2 - 4ac)$$
where we recognize our classical $b^2-4ac$.
