# Differentiate an anti-derivative function
f <- function(x) sin(x)*sqrt(1+sin(x))
F <- function(x)
integrate(f, 0, x, rel.tol = 1e-12)$value
x0 <- 1
dF0 <- numderiv(F, x0, accuracy = 6.5e-15) #=> 1.141882942715462
f(x0) # 1.141882942715464 true value
# fderiv(F, x0) # 1.141882942704476
# numDeriv::grad(F, x0) # 1.141882942705797
# Compare over a whole period
x <- seq(0, 2*pi, length.out = 11)
max(abs(numdiff(sin, x) - cos(x))) #=> 1.61e-15
# max(abs(numDeriv::grad(sin, x) - cos(x))) # 7.70e-12
Run the code above in your browser using DataLab