Roots Package Resulting in Different Roots if adding another zeros to interval

Hi all,

I am trying to find roots of this equation:

490x + 2450 e^{-x/50} - 2450 = 0

I use this code:

using Roots

f(x) = 490x + 2450*(exp(-x/50)) - 2450
find_zeros(f, -1000,1000000000)

the results are
2-element Vector{Float64}:
** -180.74752135437652**
** 1.7919879079366315e-16**

Now if I add 2 zeros the number change, to become smaller, why is this happening?

using Roots

f(x) = 490x + 2450*(exp(-x/50)) - 2450
find_zeros(f, -1000,100000000000)

2-element Vector{Float64}:
** -180.74752135437652**
** 5.738679610848498e-17**

If the interval is only from (-1000,1000) then the results are

using Roots

f(x) = 490x + 2450*(exp(-x/50)) - 2450
find_zeros(f, -1000,1000)

2-element Vector{Float64}:
** -180.74752135437652**
** 0.0**

The problem is even if the second root is converging to zero, the results are changing for different interval.

Why is the larger the interval the roots can be computed more precisely? not just 0 as root.

julia> eps(Float64)
2.220446049250313e-16

All of those are below machine precision, so are effectively zero. You just cannot compute any more accurately than that.

2 Likes

Okay thank you for the explanation

The difference is a bit of an artifact of the underlying (very heuristic) algorithm. More rigorous searches for roots over a wide interval are available by IntervalRootFinding (which identifies that zero at 0.0 with Root([-6.71673e-10, 7.33042e-10], :unique)). With find_zeros really wide search intervals will sometimes have the zero identified by a non-bracketing solutions, which, as here, converge to a zero, but up to tolerances, as already explained. When you pass the smaller interval, that zero at 0.0 is handled by a bracketing algorithm, and the answer is more in line with your mathematical expectation. For this problem, you can see that nothing bigger than 10, say, could lead to a problem, so 100000000000 is overkill for an endpoint of your search.