[R] Trig functions strange results

Ben Bolker bolker at ufl.edu
Tue Jul 14 20:38:37 CEST 2009




Nair, Murlidharan T wrote:
> 
> I am trying to calculate coordinate transformations and in the process of
> debugging my code using debug I found the following
> 
> Browse[1]> direction[i]
> [1] -1.570796
> Browse[1]> cos(direction[i])
> [1] 6.123032e-17
> Browse[1]> cos(-1.570796)
> [1] 3.267949e-07
> Browse[1]> direction[i]
> [1] -1.570796
> Browse[1]> cos(direction[i])
> [1] 6.123032e-17
> Browse[1]> cos(-1.570796)
> [1] 3.267949e-07
> Browse[1]> x<-direction[i]
> Browse[1]> x
> [1] -1.570796
> Browse[1]> cos(x)
> [1] 6.123032e-17
> 
> I am not sure why I am getting one values when I am using a variable that
> stores the value and another when I use the value directly.  Am I missing
> something here? 
> 
> 

Because you are not looking at the full precision of the data.  Try
print(x,digits=20) ...

  Ben Bolker
-- 
View this message in context: http://www.nabble.com/Trig-functions-strange-results-tp24484518p24485352.html
Sent from the R help mailing list archive at Nabble.com.




More information about the R-help mailing list