[R] plot representation of calculated value known to be 7.4

Troels Ring tring at gvdnet.dk
Mon Dec 25 20:00:09 CET 2017


Dear friends - copy paste missed

SID <- c() before the first loop - sorry

BW Troels


Den 25-12-2017 kl. 19:12 skrev Troels Ring:
>
> Dear friends - merry Christmas and thanks a lot for much help during 
> the year!
>
> In the example below I fail to understand how the calculated value pH 
> is represented in a simple plot - also included. The calculations are 
> useful in practice and likely to be right in principle but I cannot 
> see how this occurs: why a calculated value of 7.4 known as numeric is 
> not simply plotted as such. It happened on Windows both 7 and 10 with 
> R version 3.4.1.
>
> All best wishes
>
> Troels
>
> ff <- function(H,SID,ATOT,ka)  H + SID - kw/H - ka*ATOT/(H+ka)
>  ka <- 1e-7
>  kw <- 1e-14
>  ATOT <- seq(0,0.3,length=100)*1e-3
>
>  for (i in 1:length(ATOT))  {
>  SID[i] <- 
> uniroot(ff,c(-1,1),tol=.Machine$double.eps,maxiter=100000,ka=ka,
> ATOT=ATOT[i], H = 10^-7.4)$root}
> ATOT
>
> #confirm pH 0 7.4
>
> H <- c()
>  for (i in 1:length(ATOT))  {
>  H[i] <- 
> uniroot(ff,c(1e-19,1),tol=.Machine$double.eps,maxiter=100000,ka=ka,
> ATOT=ATOT[i], SID = SID[i])$root}
>
> (pH <- -log10(H))
> plot(pH)
> str(pH)
> # num [1:100] 7.4 7.4 7.4 7.4 7.4 ...
> z <- rep(7.4,length(ATOT))
> all.equal(z,pH)
> #TRUE
> points(z,col="red")
>



More information about the R-help mailing list