# ERROR: LoadError: DomainError: in quaternion(::Array{Float64,2})

**URL:** <https://discourse.julialang.org/t/error-loaderror-domainerror-in-quaternion-array-float64-2/1822>\
**Category:** General Usage\
**Created:** [February 1, 2017, 3:59pm UTC](https://discourse.julialang.org/t/error-loaderror-domainerror-in-quaternion-array-float64-2/1822 "2017-02-01T15:59:13Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![phillefjonk](https://avatars.discourse-cdn.com/v4/letter/p/f04885/32.png) [@phillefjonk](https://discourse.julialang.org/u/phillefjonk)\
**Post date:** [February 1, 2017, 3:59pm UTC](https://discourse.julialang.org/t/error-loaderror-domainerror-in-quaternion-array-float64-2/1822/1 "2017-02-01T15:59:13Z")

</div>

I get the error message

`ERROR: LoadError: DomainError: in quaternion(::Array{Float64,2})`

when I run the the following script (test5.jl):

```julia
function quaternion(m)

       q = [0.0,0.0,0.0,0.0]                   
         
       q[1] = 0.5*sqrt(1+ m[1,1] + m[2,2]+ m[3,3])                
        if q[1] == 0.0                                            
         q[1] = eps()                                                 
        end 
       q[2] = (1/(4*q[1]))*(m[3,2] - m[2,3])
       q[3] = (1/(4*q[1]))*(m[1,3] - m[3,1])
       q[4] = (1/(4*q[1]))*(m[2,1] - m[1,2])

       return q

end

lat = 8.7758905947561e-8
lon = 0.0

C_ne(lat,lon) = [-8.77589e-8 -0.0 -1.0; -0.0 1.0 -0.0; 1.0 0.0 -8.77589e-8]
C__eb = [0.5 0.0 -1.0; 0.0 1.0 0.0; 1.0 0.0 2.22045e-16]

C __nb = C__ eb * C_ne(lat,lon)
# C__nb= [-1.0 0.0 -0.5; 0.0 1.0 -0.0; -8.77589e-8 0.0 -1.0]

s = quaternion(C__nb)

println("s= ",s)

```

But if I switch to (i.e. load C\_\_nb manually)

```julia
<code>

# C __nb = C__ eb * C_ne(lat,lon)
C__nb= [-1.0 0.0 -0.5; 0.0 1.0 -0.0; -8.77589e-8 0.0 -1.0]

<code>

```

The code executes fine:

```julia
$ julia test5.jl 
s= [2.22045e-16,0.0,-5.6295e14,0.0]

```

Why do I get an execution error in my function quaternion(m) when the matrix C\_\_nb is computed?

---

<div class="post-metadata">

**Author:** ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)\
**Post date:** [February 1, 2017, 4:06pm UTC](https://discourse.julialang.org/t/error-loaderror-domainerror-in-quaternion-array-float64-2/1822/2 "2017-02-01T16:06:39Z")

</div>

Because you are taking the `sqrt` of a negative real number. Convert it to a complex number first if it can be negative.

---

<div class="post-metadata">

**Author:** ![phillefjonk](https://avatars.discourse-cdn.com/v4/letter/p/f04885/32.png) [@phillefjonk](https://discourse.julialang.org/u/phillefjonk)\
**Post date:** [February 1, 2017, 4:22pm UTC](https://discourse.julialang.org/t/error-loaderror-domainerror-in-quaternion-array-float64-2/1822/3 "2017-02-01T16:22:33Z")

</div>

OK now I see,

When I compute C\_\_nb the value of (1+ m[1,1] + m[2,2]+ m[3,3]) becomes: -4.38794500734474e-8

But when I copy the result of the expression C\_\_nb = C\_\_eb \* C\_ne(lat,lon) from a println(C\_\_nb) and use it “manually”, the evaluation of (1+ m[1,1] + m[2,2]+ m[3,3]) becomes: 0.0

Suttle…

Thanks!
