# [R] uniroot problem

Troels Ring tr|ng @end|ng |rom gvdnet@dk
Fri Sep 16 08:05:22 CEST 2022

```Dear friends - I have a problem with root finding using uniroot as goes:

I have the function

ASTA <- function(SID,H,ATOT,KA) {H + SID - kw/H - ATOT*KA/KA+H }

I know SID = 0.01199 - and I know H = 10^-4.57 - and I know kw = 1e-14

Therefore, as I make KA = 10^-seq(1,10,length=100), by letting ASTA = 0,
I can find ATOT for each KA as

ATOT <-  (H+SID-kw/H)*(KA+H)/KA

and

summary(ATOT) =    Min.  1st Qu.   Median     Mean  3rd Qu. Max.
0.012    0.013    0.115 171.263
18.278 3234.407

However, if I make use of uniroot by:

KA <- seq(1,10,length=100)
KA <- 10^-KA

ATOT <- c()

for (i in 1:100) {
ATOT[i] <- uniroot(ASTA,c(-1e3,1e3),tol=1e-20,maxiter=1e4,
SID=SID,KA=KA[i],H=10^-pH[1])\$root
}

I get 100 identical ATOT values of 0.01204383 and no warnings.

I'm on Windows 10, using slightly old

\$version.string
[1] "R version 4.0.5 (2021-03-31)"

Best wishes

Troels Ring, MD
Aalborg, Denmark

```