# Why would these errors pop up?

**URL:** https://discourse.julialang.org/t/why-would-these-errors-pop-up/57330
**Category:** General Usage
**Tags:** question
**Created:** [March 16, 2021, 7:33pm UTC](https://discourse.julialang.org/t/why-would-these-errors-pop-up/57330 "2021-03-16T19:33:35Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![redlush](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/redlush/32/21015_2.png) [@redlush](https://discourse.julialang.org/u/redlush)
#### Post date: [March 16, 2021, 7:33pm UTC](https://discourse.julialang.org/t/why-would-these-errors-pop-up/57330/1 "2021-03-16T19:33:35Z")

</div>

Hi all. I am new to Julia and not familiar on troubleshooting my code in this language. I have constructed a block matrix constructed of smaller block matrices - a diagonal one and then an off diagonal one. The construction follows from a function I did, and if I diagonalize this matrix, it returns the respective eigenvalues from it. The matrix has a dimensionality 4N x 4N where N comes from another function - this is a little irrelevant, since I have proven it all works.

Well, when I try to get multiple arrays of eigenvalues following from the variables I feed into the function, I get the following errors:

```julia
InexactError: Float64(-8987.992438638395 - 0.008932123138978246im)

Stacktrace:
 [1] Real at .\complex.jl:37 [inlined]
 [2] convert at .\number.jl:7 [inlined]
 [3] setindex! at .\array.jl:849 [inlined]
 [4] macro expansion at .\multidimensional.jl:802 [inlined]
 [5] macro expansion at .\cartesian.jl:64 [inlined]
 [6] macro expansion at .\multidimensional.jl:797 [inlined]
 [7] _unsafe_setindex!(::IndexLinear, ::Array{Float64,2}, ::Array{Complex{Float64},1}, ::Int64, ::Base.Slice{Base.OneTo{Int64}}) at .\multidimensional.jl:789
 [8] _setindex! at .\multidimensional.jl:785 [inlined]
 [9] setindex!(::Array{Float64,2}, ::Array{Complex{Float64},1}, ::Int64, ::Function) at .\abstractarray.jl:1153
 [10] top-level scope at .\In[38]:4
 [11] include_string(::Function, ::Module, ::String, ::String) at .\loading.jl:1091

```

Coming from a python background I find it hard to check where my errors are located at. Can someone help me recognize this error and where to find some additional information about it?

---

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [March 16, 2021, 7:45pm UTC](https://discourse.julialang.org/t/why-would-these-errors-pop-up/57330/2 "2021-03-16T19:45:42Z")

</div>

It would be better if you provided a minimal working example. But it seems that you are getting complex eigenvalues and trying to add them into a an array which is set to be of `Float64` numbers?

The explicit meaning of the error is just this, for example:

```julia
julia> x = sqrt(Complex(-1))
0.0 + 1.0im

julia> Float64(x)
ERROR: InexactError: Float64(0.0 + 1.0im)
Stacktrace:
 [1] Float64(::Complex{Float64}) at ./complex.jl:37
 [2] top-level scope at REPL[22]:1

julia> y = [1.0,2.0]
2-element Array{Float64,1}:
 1.0
 2.0

julia> y[1] = x
ERROR: InexactError: Float64(0.0 + 1.0im)
Stacktrace:
 [1] Real at ./complex.jl:37 [inlined]
 [2] convert at ./number.jl:7 [inlined]
 [3] setindex!(::Array{Float64,1}, ::Complex{Float64}, ::Int64) at ./array.jl:847
 [4] top-level scope at REPL[26]:1

```

Somewhere a complex value is trying to be converted to a Float64, maybe to be added to a vector of floats.

---

<div class="post-metadata">

### Author: ![redlush](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/redlush/32/21015_2.png) [@redlush](https://discourse.julialang.org/u/redlush)
#### Post date: [March 23, 2021, 7:37pm UTC](https://discourse.julialang.org/t/why-would-these-errors-pop-up/57330/3 "2021-03-23T19:37:52Z")

</div>

That’s exactly what was happening, thank you!
