-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path4_1.R
More file actions
44 lines (33 loc) · 685 Bytes
/
4_1.R
File metadata and controls
44 lines (33 loc) · 685 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#' ###
#' APTS 4. "Some exercises"
#' ###
rm(list=ls())
# Question 1 --------------------------------------------------------------
# a)
eps <- 1
x <- 1
while(x + eps != x) eps <- eps/2
eps/x
# b)
x == x + eps #TRUE
# c)
2*eps == .Machine$double.eps # TRUE
# d)
epsx <- function(x){
eps <- 1
while(x + eps != x) eps <- eps/2
return(eps/x)
}
store <- list()
p <- 1
for(i in c(1/8, 1/4, 1/2, 1, 2, 4, 8)){
store[[p]] <- epsx(i)
p <- p+1
}
length(which(store == epsx(1/2))) # Cant remember how to use isTRUE(all)!
# e)
epsx(2+1e-5) # Not the same number
# f)
small.inc <- 1e-16
while(epsx(2 + small.inc) == epsx(2)) small.inc <- small.inc * 10
# 16 decimal places(?)