#Contoh 2.1.1#
contoh211 <- function(expr, age, t) {
sxt <- eval({x=age+t; expr})
sx <- eval({x=age; expr})
output <- (sx-sxt) / sx
output
}
expr <- expression(1-(x/100))
contoh211 (expr, age=30, t=10)
## [1] 0.1428571
#Contoh 2.1.2#
contoh212 <- function(expr, age, t) {
sxt <- eval({x=age+t; expr})
sx <- eval({x=age; expr})
output <- (sx-sxt) / sx
output
}
expr <- expression((1-(x/100))^0.5)
contoh212 (expr, age=36, t=15)
## [1] 0.125
1-contoh212 (expr, age=19, t=17)
## [1] 0.8888889
#Contoh 2.1.3#
contoh213 <- function(expr, age, t) {
sxt <- eval({x=age+t; expr})
sx <- eval({x=age; expr})
output <- (sx-sxt) / sx
output
}
expr <- expression(exp(-x/12))
tpx <- 1-contoh213(expr, age=13, t=7)
tpx
## [1] 0.5580351
tqx <- contoh213(expr, age=20, t=1)
tqx
## [1] 0.07995559
tpx*tqx
## [1] 0.04461803