MATLAB: Anyone have a clue why roots([1,6,9]) outputs complex numbers

roots

a = roots([1,6,9])
I was using roots to output the roots of the equation x^2+6x+9=0
this gives:
a =
-3.0000 + 0.0000i
-3.0000 – 0.0000i
when I use other values that create a quadratic equation with equal roots it seems to work fine, can someone explain to me why this is the case?

Best Answer

If you switch to format long you will see non zero imaginary parts. Those are caused by roundoff problems with solving the Vandermode system to get the roots.
Related Question