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")
______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.