I have two non-linear equations for which I want to find all roots.
Using nlsolve only returns one root.
How can I configure it to return all roots, say in some range of parameters?
You may be interested in IntervalRootFinding.jl. Here’s a tutorial: https://github.com/JuliaIntervals/IntervalRootFinding.jl.
edit:
The tutorial is actually here:
Interval root finding tutorial
Thanks, this package indeed seems to do the job!
However, I am having a hard time to take the actual number out of the returned interval.
The returned roots are put in rts and they are
3-element Vector{Root{IntervalBox{2, Float64}}}:
Root([-0.261043, -0.261042] × [0.722688, 0.722689], :unique)
Root([0.26962, 0.269621] × [0.26962, 0.269621], :unique)
Root([0.722688, 0.722689] × [-0.261043, -0.261042], :unique)
So rts[1].interval[1] gives back the first interval [-0.261043, -0.261042]. I want to get one number from this so I can plot it or do other operations with it.
When I run first(rts[1].interval[1]) I still get the entire interval [-0.261043, -0.261042].
I looked in the documentation and didn’t find a specification on how to do that. If you happen to know, I would love the help:)
For practical purposes, I would check that the interval is sufficiently narrow (below some \epsilon) and then just take a midpoint or something similar.
yes, this is exactly what I had in mind.
The problem is that I don’t know how to get the bounds of the interval object.
You can extract the low and high value of an interval as
low, high = interval.lo, interval.hi
thanks! this works! perhaps you can point me to where in the docs I can find more useful operations?
Please refer to Interval arithmetic tutorial for more operations on the interval. However, there is no docs for .lo and .hi. I find these fields in the source code.
An easy way to learn about fields inside types is using typeof and fieldnames. Following the same setup in the tutorial, you can do:
julia> rts
2-element Vector{Root{Interval{Float64}}}:
Root([1.99999, 2.00001], :unique)
Root([-1.72982e-09, 1.38862e-09], :unique)
julia> rts |> typeof
Vector{Root{Interval{Float64}}} (alias for Array{Root{Interval{Float64}}, 1})
julia> rts[1] |> typeof |> fieldnames
(:interval, :status)
julia> rts[1].interval |> typeof |> fieldnames
(:lo, :hi)