Search code examples
matlabmatrixsymbolic-mathpolynomialseigenvalue

The roots of the characteristic polynomial and the eigenvalues are not the same


This is matrix B

B = [1 2 0 ; 2 4 6 ; 0 6 5]

The result of eig(B) is:

{-2.2240, 1.5109, 10.7131}

and the characteristic polynomial of B by this link is

syms x
polyB = charpoly(B,x)
x^3 - 10*x^2 - 11*x + 36

but the answer of solve(polyB) is

133/(9*(3^(1/2)*5492^(1/2)*(i/3) + 1009/27)^(1/3)) + ((3^(1/2)*5492^(1/2)*i)/3 + 1009/27)^(1/3) + 10/3
 (3^(1/2)*(133/(9*(3^(1/2)*5492^(1/2)*(i/3) + 1009/27)^(1/3)) - ((3^(1/2)*5492^(1/2)*i)/3 + 1009/27)^(1/3))*i)/2 - 133/(18*(3^(1/2)*5492^(1/2)*(i/3) + 1009/27)^(1/3)) - ((3^(1/2)*5492^(1/2)*i)/3 + 1009/27)^(1/3)/2 + 10/3
 10/3 - 133/(18*(3^(1/2)*5492^(1/2)*(i/3) + 1009/27)^(1/3)) - ((3^(1/2)*5492^(1/2)*i)/3 + 1009/27)^(1/3)/2 - (3^(1/2)*(133/(9*(3^(1/2)*5492^(1/2)*(i/3) + 1009/27)^(1/3)) - ((3^(1/2)*5492^(1/2)*i)/3 + 1009/27)^(1/3))*i)/2

which I don't know what it is while I expect it to be the eigenvalues of B. What is the problem?


Solution

  • I do not understand why you add x and symbolic maths, they are not required for your task.

    B = [1 2 0 ; 2 4 6 ; 0 6 5]
    cp=charpoly(B)
    eig2=roots(cp)
    

    returns:

    eig2 =
    
       10.7131
       -2.2240
        1.5109
    

    However, if for some reason you insist in using symbolic (which you should not for a numerical task), you can do

    double(solve(polyB))
    
    ans =
    
      10.7131 + 0.0000i
      -2.2240 - 0.0000i
       1.5109 - 0.0000i
    

    (note imaginary parts is zero)