Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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
share|improve this question

closed as too localized by m_goldberg, Yves Klett, whuber, Artes, rm -rf May 7 '13 at 14:19

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

    
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. –  bill s May 7 '13 at 4:57
    
@bills it's not the problem of calculating eigenvalues. –  matheorem May 7 '13 at 4:58
    
See this for a discussion of machine precision arithmetic in Mathematica: reference.wolfram.com/mathematica/tutorial/… –  bill s May 7 '13 at 5:08
    
@bills thank you bill s. OK, I understand. –  matheorem May 7 '13 at 5:20

1 Answer 1

up vote 7 down vote accepted

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.

share|improve this answer
    
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]]. –  J. M. May 7 '13 at 7:43

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