The DomainError
is caused because you are taking the square root of a negative real number, and the workaround is to cast it to complex:
julia> (-1)^0.5
ERROR: DomainError with -1.0:
Exponentiation yielding a complex result requires a complex argument.
Replace x^y with (x+0im)^y, Complex(x)^y, or similar.
...
julia> (Complex(-1))^0.5 # workaroud
0.0 + 1.0im
The InexactError
is caused because you are trying to store the complex number calculated above in a vector of real numbers. Your Cvvals
is a vector of Float64
, but kterms()
is generating a complex number because it calculates the output using the complex number obtained by square-rooting a negative number as above.
In the error message, the output Float64(0.5141891571782113 - 1.6389735916551083e-6im)
generated by kterms()
seems to be nearly real, and the imaginary part seems to be just a rounding error. If you are sure that kterms()
should return always real numbers, discard its imaginary part and take only the real part when storing in Cvvals
.