GD <- Grid(nlevels = c("x" = 20, "y" = 20))
x <- levels(GD)[[1]]; y <- levels(GD)[[2]]
f <- apply_Grid(GD, branin)
dim(f) <- nlevels(GD)
contour(x = x, y = y, z = f, nlevels = 40)
nOut <- 100; Xout2 <- array(runif(nOut * 2), dim = c(nOut, 2))
colnames(Xout2) <- c("x", "y")
## interpolate using default method (Lagrange)
GIL <- interp_Grid(X = GD, Y = f, Xout = Xout2)
## interpolate using a natural spline
GIS <- interp_Grid(X = GD, Y = f, Xout = Xout2,
cardinalBasis1d = function(x, xout) {
cardinalBasis_natSpline(x = x, xout = xout)$CB
})
F <- apply(Xout2, 1, branin)
mat <- cbind(Xout2, fTrue = F, fIntL = GIL, errorLag = F - GIL,
fIntS = GIS, errorSpline = F - GIS)
apply(mat[ , c("errorLag", "errorSpline")], 2, function(x) mean(abs(x)))
## Not run:
# ## for the users of the "rgl" package only...
# library(rgl)
# persp3d(x = x, y = y, z = f, aspect = c(1, 1, 0.5), col = "lightblue", alpha = 0.8)
# spheres3d(Xout2[ , 1], Xout2[ , 2], GIS, col = "orangered",
# radius = 2)
# ## End(Not run)
Run the code above in your browser using DataLab