# \donttest{
# Example 1: unique minimum at (1, 1, 1)
f1 <- function(x) sum((x - 1)^2)
B <- rbind(c(-2, 3), c(-2, 3), c(-2, 3)) # 3D bounds
res1 <- critical_points_nd(
f1,
bounds = B,
start_grid = c(5, 5, 5),
n_random = 50,
seed = 1
)
res1$critical_points
# Example 2: saddle at the origin in 3D
f2 <- function(x) x[1]^2 + x[2]^2 - x[3]^2
B2 <- rbind(c(-1, 1), c(-1, 1), c(-1, 1))
res2 <- critical_points_nd(
f2,
bounds = B2,
start_grid = c(5, 5, 5),
n_random = 30,
seed = 123
)
res2$critical_points
# Example 3 (4D): multiple critical points
f3 <- function(x) sum(x^4 - 2 * x^2)
B3 <- do.call(rbind, replicate(4, c(-2, 2), simplify = FALSE))
res3 <- critical_points_nd(
f3,
bounds = B3,
start_grid = rep(4, 4),
n_random = 200,
seed = 42
)
head(res3$critical_points)
# }
Run the code above in your browser using DataLab