InexactError: show_trace not work for complex numbers
Closed this issue · 5 comments
One can use this code to reproduce the error
find_zero(sin, 1.0+1.0im, Order1(), verbose = true)
Interesting. I was going to write back that we have a pretty strong assumption that the x values are real, save for Newton's method, but that isn't really the case, as it appears the secant method works with a complex valued starting point. This is just about the print method for verbose=true
. I'll see if something can be done. Right now we use @sprintf
so hopefully it is just an adjustment of the flag we use.
In the meantime, if you want to see your trace, you could do something like this:
T = Complex{Float64}
tracks = Roots.Tracks(T,T)
find_zero(sin, 3.0+1.0im, Roots.Order1(); tracks=tracks)
tracks.xfₛ
I think the only method that needs to be changed is show_tracks.
We only need two functions to handle real and complex, say
where {T <: Real}
where {T <: Complex}
Here is the version for complex
function show_tracks(io::IO, s::Roots.Tracks{ComplexF64, ComplexF64}, M::Roots.AbstractUnivariateZeroMethod)
# show (x,f(x))
for (i, (xi, fxi)) in enumerate(s.xfₛ)
println(
io,
@sprintf(
"%s%s = (%.17g, %.17g),\t %s%s = (%.17g, %.17g)",
"x",
sprint(io -> Roots.unicode_subscript(io, i)),
real(xi), imag(xi),
"fx",
sprint(io -> Roots.unicode_subscript(io, i)),
real(fxi), imag(fxi)
)
)
end
# show bracketing
i₀ = length(s.xfₛ)
for (i, (a, b)) in enumerate(s.abₛ)
j = i₀ + i
println(
io,
@sprintf(
"(%s%s, %s%s) = ( %.17g, %.17g )",
"a",
sprint(io -> unicode_subscript(io, j - 1)),
"b",
sprint(io -> unicode_subscript(io, j - 1)),
a,
b
)
)
end
println(io, "")
end
Wow, I was about to write just what you wrote and voila, code already there!. Let me put it into a PR, unless you did that already.