Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error root #453

Open
jmarcellopereira opened this issue Dec 28, 2024 · 4 comments
Open

Error root #453

jmarcellopereira opened this issue Dec 28, 2024 · 4 comments

Comments

@jmarcellopereira
Copy link

An error occurs when using Roots.jl to solve an equation, the result should be -2.0, not -1.58. The error only occurs when I use uncertainties.

using Measurements, Roots

a = measurement(1.0 , 0.1)
b = measurement(-3.0 , 0.1)
c = measurement(-10.0, 0.1)

f(x) = ax^2 + bx + c

find_zero(f, measurement(0.0, 0.1))

−1.58±0.12

@jverzani
Copy link
Member

Thanks for the report. I'll investigate soon.

@jverzani
Copy link
Member

jverzani commented Jan 5, 2025

Did 2.2.3 fix this?

@jmarcellopereira
Copy link
Author

jmarcellopereira commented Jan 6, 2025

Hi jverzani

using Measurements, Roots

a = measurement(1.0 , 0.1)
b = measurement(-3.0 , 0.1)
c = measurement(-10.0, 0.1)

f(x) = a*x^2 + b*x + c

Pkg.status("Roots"), find_zero(f, measurement(0.0, 0.1)), find_zero(f, measurement(0.5, 0.1)), find_zero(f, measurement(-1.0, 0.1))

Status `~/.julia/environments/v1.11/Project.toml`
⌃ [f2b01f46] Roots v2.2.1
Info Packages marked with ⌃ have new versions available and may be upgradable.

(nothing, -1.58 ± 0.12, -2.0 ± 0.065, -1.968 ± 0.063)

The error still persists, but when I approximate the initial value of the root the result is consistent. Thanks for answering.

@jverzani
Copy link
Member

jverzani commented Jan 6, 2025

Thanks for following up.

In this example, the issue becomes clearer. Internally, we have some checks to terminate early if an exact zero is found using iszero, but as was pointed out, strictly speaking a value like measurement(0.0, .01) is not a zero (as Roots is expecting). This comes up in the Alefeld Potra Shi algorithms, but not Bisection. You might have more luck using this call instead of the default

find_zero(f, x, Secant(), Bisection())

With this, the following returns what you want over a range of values

a = measurement(1.0 , 0.1)
b = measurement(-3.0 , 0.1)
c = measurement(-10.0, 0.1)

f(x) = a*x^2 + b*x + c

for x in range(-3, 6, 100)
	@show x, find_zero(f, measurement(x, 0.1), Secant(), Bisection())
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants