# plot representation of calculated value known to be 7.4

6 messages
Open this post in threaded view
|

## plot representation of calculated value known to be 7.4

 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") ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: plot representation of calculated value known to be 7.4

 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") > ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: plot representation of calculated value known to be 7.4

 Note that ?all.equal clearly says that it tests for **approximate equality only** with tolerance "close to 1.5 e-8. So.. > all.equal(z,pH, tol = 1e-15) [1] "Mean relative difference: 6.732527e-11" and > print(pH, digits =15) ## output omitted Shows you what's going on. Cheers, Bert Bert Gunter "The trouble with having an open mind is that people keep coming along and sticking things into it." -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) On Mon, Dec 25, 2017 at 11:00 AM, Troels Ring <[hidden email]> wrote: > 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") >> >> > ______________________________________________ > [hidden email] 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/posti> ng-guide.html > and provide commented, minimal, self-contained, reproducible code. >         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.
Open this post in threaded view
|

## Re: plot representation of calculated value known to be 7.4

 In reply to this post by tring Thanks a lot - formatting the ordinate as ylim=c(4,10) before plotting pH also removed the problem, and options(digits=10) confirmed that pH was not all exactly 7.4 - as I knew. Still I wonder just why R chooses to plot(ATOT,pH) as shown with repeated "7.4" instead of some more detailed representation. Thanks a gain and happy New Year! Troels Den 26-12-2017 kl. 01:03 skrev Bert Gunter: > Note that ?all.equal clearly says that it tests for **approximate > equality only** with tolerance "close to 1.5 e-8. > > So.. > > > all.equal(z,pH, tol = 1e-15) > [1] "Mean relative difference: 6.732527e-11" > > and > > > print(pH, digits =15) > ## output omitted > > Shows you what's going on. > > Cheers, > Bert > > > > Bert Gunter > > "The trouble with having an open mind is that people keep coming along > and sticking things into it." > -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip ) > > On Mon, Dec 25, 2017 at 11:00 AM, Troels Ring <[hidden email] > > wrote: > >     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") > > >     ______________________________________________ >     [hidden email] 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. > >         [[alternative HTML version deleted]] ______________________________________________ [hidden email] mailing list -- To UNSUBSCRIBE and more, see https://stat.ethz.ch/mailman/listinfo/r-helpPLEASE do read the posting guide http://www.R-project.org/posting-guide.htmland provide commented, minimal, self-contained, reproducible code.