3
$\begingroup$

I encountered a problem. I have a eigenvector eigvsI[1]

eigvsI[1]={0.0161028 - 0.0119647 I, 0.111551 - 0.0828846 I, 0.20484 - 0.1522 I, 
0.249467 - 0.185359 I, 0.28268 - 0.210037 I, 
0.301895 - 0.224314 I, -0.190871 + 0.141821 I, -0.271275 + 
0.201562 I, -0.244686 + 0.181807 I, -0.204743 + 
0.152128 I, -0.148422 + 0.11028 I, -0.0281275 + 0.0208993 I}

and a hermite matrix hI[1]

    hI[1]={{0, Sqrt[5]/2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {Sqrt[5]/2, 0, Sqrt[2],
0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, Sqrt[2], 0, 3/2, 0, 0, 0, 0, 0, 0, 
0, 0}, {0, 0, 3/2, 0, Sqrt[2], 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, Sqrt[
2], 0, Sqrt[5]/2, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, Sqrt[5]/2, 0, 0, 
0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, Sqrt[5]/2, 0, 0, 0, 0}, {0, 0,
0, 0, 0, 0, Sqrt[5]/2, 0, Sqrt[2], 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 
Sqrt[2], 0, 3/2, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 3/2, 0, Sqrt[2], 
0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, Sqrt[2], 0, Sqrt[5]/2}, {0, 0, 0, 0,
0, 0, 0, 0, 0, 0, Sqrt[5]/2, 0}}

theoretically

Conjugate[eigvsI[1]].hI[1].eigvsI[1]

should be Real number. But MMA gives

-0.253172 - 8.00544*10^-18 I

where does this small imaginary part come from?

On the other hand,

Conjugate[eigvsI[1]].eigvsI[1]

gives perfect zero imaginary part

0.811081 + 0. I
$\endgroup$
4
  • $\begingroup$ Calculating eigenvalues involves factoring a large polynomial (the characteristic polynomial) and routines for factoring often "miss" by small amounts, causing small imaginary parts. I would just use Chop to remove the bear-zero parts. $\endgroup$
    – bill s
    Commented May 7, 2013 at 4:57
  • $\begingroup$ @bills it's not the problem of calculating eigenvalues. $\endgroup$
    – matheorem
    Commented May 7, 2013 at 4:58
  • $\begingroup$ See this for a discussion of machine precision arithmetic in Mathematica: reference.wolfram.com/mathematica/tutorial/… $\endgroup$
    – bill s
    Commented May 7, 2013 at 5:08
  • $\begingroup$ @bills thank you bill s. OK, I understand. $\endgroup$
    – matheorem
    Commented May 7, 2013 at 5:20

1 Answer 1

9
$\begingroup$

The numbers you have, like 0.0161028 - 0.0119647 I are floating point (machine precision) numbers. Whenever you do calculations with floating point numbers, you will get roundoff errors. Note that you appear to have 7 or 8 digits of accuracy in the numbers. The "error" in the imaginary part is in the 18th decimal place. This is roundoff error. See this for a discussion of machine precision arithmetic in Mathematica. The simplest way to remove such round-off errors is to use Chop, which replaces approximate real numbers that are close to zero with the exact number 0. This effectively removes the imaginary part from a number like -0.253172 - 8.00544*10^-18 I.

$\endgroup$
2
  • $\begingroup$ If OP absolutely doesn't want to use Chop[]: Re[eigvsI[1]].hI[1].Re[eigvsI[1]] + Im[eigvsI[1]].hI[1].Im[eigvsI[1]]. $\endgroup$ Commented May 7, 2013 at 7:43
  • $\begingroup$ @bill s Is there a way to apply Chop to intermediate results of iterative processes such as NDSolve? $\endgroup$
    – Janosh
    Commented Feb 1, 2017 at 15:35

Not the answer you're looking for? Browse other questions tagged or ask your own question.