# Eigenvalues are approximately correct, not exactly

**URL:** https://discourse.julialang.org/t/eigenvalues-are-approximately-correct-not-exactly/78952
**Category:** New to Julia
**Tags:** linearalgebra, eigenvalues
**Created:** [April 3, 2022, 4:27pm UTC](https://discourse.julialang.org/t/eigenvalues-are-approximately-correct-not-exactly/78952 "2022-04-03T16:27:19Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![Vahid\_Hosseinzadeh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vahid_hosseinzadeh/32/33293_2.png) [@Vahid\_Hosseinzadeh](https://discourse.julialang.org/u/Vahid_Hosseinzadeh)
#### Post date: [April 3, 2022, 4:27pm UTC](https://discourse.julialang.org/t/eigenvalues-are-approximately-correct-not-exactly/78952/1 "2022-04-03T16:27:19Z")

</div>

Hi everybody,

```julia
using LinearAlgebra
eigvals([0. 1im;1im 0.]) 

```

gives:

```julia
2-element Vector{ComplexF64}:
                    0.0 + 0.9999999999999997im
 2.7755575615628914e-17 - 1.0im

```

which is correct but with approximation. I am new to Julia and wondering if anything I’m missing or not. The question actually is how eigvals actually works.  
Thank you all

---

<div class="post-metadata">

### Author: ![ctkelley](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ctkelley/32/10684_2.png) [@ctkelley](https://discourse.julialang.org/u/ctkelley)
#### Post date: [April 3, 2022, 5:21pm UTC](https://discourse.julialang.org/t/eigenvalues-are-approximately-correct-not-exactly/78952/2 "2022-04-03T17:21:32Z")

</div>

eigvals is an iterative method, even for problems this small. So it seesm that you got something reasonable.

---

<div class="post-metadata">

### Author: ![poopsilon](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/poopsilon/32/35351_2.png) [@poopsilon](https://discourse.julialang.org/u/poopsilon)
#### Post date: [April 3, 2022, 5:44pm UTC](https://discourse.julialang.org/t/eigenvalues-are-approximately-correct-not-exactly/78952/3 "2022-04-03T17:44:18Z")

</div>

When dealing with floats, you should in general expect answers that are “correct but with approximation”, because of the way floating numbers are stored internally.

As another illustration of this, consider

```julia
julia> .1 + .2
0.30000000000000004

```

---

<div class="post-metadata">

### Author: ![jonniedie](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jonniedie/32/12842_2.png) [@jonniedie](https://discourse.julialang.org/u/jonniedie)
#### Post date: [April 3, 2022, 9:07pm UTC](https://discourse.julialang.org/t/eigenvalues-are-approximately-correct-not-exactly/78952/4 "2022-04-03T21:07:03Z")

</div>

Also, if you need more precision, you can use `BigFloat`s.

```julia
julia> eigvals([big(0) 1im; 1im 0])
2-element Vector{Complex{BigFloat}}:
 0.0 - 1.0im
 0.0 + 1.0im

```

---

<div class="post-metadata">

### Author: ![Sukera](https://avatars.discourse-cdn.com/v4/letter/s/ce7236/32.png) [@Sukera](https://discourse.julialang.org/u/Sukera)
#### Post date: [April 3, 2022, 10:01pm UTC](https://discourse.julialang.org/t/eigenvalues-are-approximately-correct-not-exactly/78952/5 "2022-04-03T22:01:51Z")

</div>

> [@PSA: floating-point arithmetic](https://discourse.julialang.org/t/psa-floating-point-arithmetic/8678):
>
> Sometimes people are surprised by the results of floating-point calculations such as julia\> 5/6 0.8333333333333334 # shouldn't the last digit be 3? julia\> 2.6 - 0.7 - 1.9 2.220446049250313e-16 # shouldn't the answer be 0? These are not bugs in Julia. They’re consequences of the IEEE-standard 64-bit binary representation of floating-point numbers that is burned into computer hardware, which Julia and many other languages use by default. Brief explanation You can t…

---

<div class="post-metadata">

### Author: ![Vahid\_Hosseinzadeh](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/vahid_hosseinzadeh/32/33293_2.png) [@Vahid\_Hosseinzadeh](https://discourse.julialang.org/u/Vahid_Hosseinzadeh)
#### Post date: [April 4, 2022, 12:47pm UTC](https://discourse.julialang.org/t/eigenvalues-are-approximately-correct-not-exactly/78952/6 "2022-04-04T12:47:47Z")

</div>

Thank you all for the answers. Sorry my question was kind of naive as my background is not CS.  
Just another question to me, maybe you put a comment on it, is: I am doing a matrix computation in which I am using FLoops.jl to parallel the computation. Here what I get from @floop and without @floop are the same only if I round up to `round.(A,digits=14)`. @floop really works here for me as it speeds up the computation 10x faster. But can you explain this and reduce this to the previous question.

---

<div class="post-metadata">

### Author: ![Jeff\_Emanuel](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jeff_emanuel/32/15440_2.png) [@Jeff\_Emanuel](https://discourse.julialang.org/u/Jeff_Emanuel)
#### Post date: [April 4, 2022, 2:50pm UTC](https://discourse.julialang.org/t/eigenvalues-are-approximately-correct-not-exactly/78952/7 "2022-04-04T14:50:21Z")

</div>

Floating point round-off depends on the order of operations. Doing calculations in parallel vs sequentially will change the order of operations.
