Skip to content

roots returns NaNs for roots with complicated function #169

@alecloudenback

Description

@alecloudenback

I am trying to build a more robust internal rate of return solver for ActuaryUtilities.jl and couldn't get IntervalRootFinding to pass some tests finding the roots. The following case failed for me.

cfs = [t % 10 == 0 ? -10 : 1.5 for t in 0:99]
f(i) =  sum(cfs .* [1/(1+i[1])^t for t in 0:length(cfs)-1])

This worked:

julia> roots(f,0..2)
1-element Vector{Root{Interval{Float64}}}:
 Root([0.0646316, 0.0646317], :unique)

But the following takes considerable time and returns a bunch of roots that are actually `N⚓

julia> roots(f,-2..2)
19662-element Vector{Root{Interval{Float64}}}:
Root([-1.00046, -1.00045], :unknown)
Root([-0.999951, -0.99995], :unknown)
Root([-1.00047, -1.00046], :unknown)
Root([-1.00066, -1.00065], :unknown)
Root([-0.999964, -0.999963], :unknown)
Root([-1.00029, -1.00028], :unknown)
Root([-1.0004, -1.00039], :unknown)
⋮
Root([-0.999918, -0.999917], :unknown)
Root([-0.999854, -0.999853], :unknown)
Root([-0.999729, -0.999728], :unknown)
Root([-0.999867, -0.999866], :unknown)
Root([-1.00032, -1.00031], :unknown)
Root([-1.00051, -1.0005], :unknown)

f shoots up towards infinity around -0.5, so maybe related to #161?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions