# ----------------------------------------------------------------------
# Programming and Data Analysis with R - Exercises A
# Exercise A
# ----------------------------------------------------------------------

rm(list = ls())

f <- function(x) {
  abs(sin(pi / (4 * x^2))) / x
}

# 1 --------------------------------------------------------------------
f(1)
f(10^8)

# 2 --------------------------------------------------------------------
round(f(1), 2)
round(f(10), 2)

# 3 --------------------------------------------------------------------
curve(f(x), 1, 3)

# 4 --------------------------------------------------------------------
K <- 500
sum(f(1:K))

# 5 --------------------------------------------------------------------
integrate(f, lower = 1, upper = 3)
