CHALLENGE using root_fortran to find root of a complex function

According to the source code of uniroot (https://github.com/SurajGupta/r-source/blob/master/src/library/stats/man/uniroot.Rd), it just calls zeroin, which uses an absolute tolerance on the interval.

The equivalent option in roots-fortran is atol. In addition you should set rtol to 0. tol1 is not part of the public interface, it is just a variable used internally. (:warning: see edit below)

The default tolerance in R’s uniroot is relatively high. The value of eps^(1/4) is about 0.0001 for 64-bit double precision. On the other hand 10^-25 is too low. I’d expect 2*eps to be the “best” you can achieve. I’d expect this accuracy to be higher than the rest of the experimentally-measured parameters in your chemical equilibrium model.

Edit 1: I’d recommend consulting an introductory textbook on numerical methods for an explanation of terms such as machine precision and absolute or relative error. One of my favorites is Computer Methods for Mathematical Computations (1977) by Forsythe, Malcolm and Moler, published by Prentice Hall. But most newer textbooks also contain an introductory chapter on how machines represent numbers and what this means for a model analyst.

Edit 2: :warning: the statements earlier are wrong, zeroin uses a relative tolerance. The option rtol in the roots-fortran method “brent” is equivalent to tol in the classic zeroin.

1 Like