R Under development (unstable) (2026-02-09 r89390 ucrt) -- "Unsuffered Consequences" Copyright (C) 2026 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > > objfun <- function(x) { + stopifnot(is.numeric(x)) + stopifnot(length(x) == 2) + f <- expression(5 * x1 + x1^2 - x2^2 + (1 / 100) * (x1^4 + x2^4)) + g1 <- D(f, "x1") + g2 <- D(f, "x2") + h11 <- D(g1, "x1") + h12 <- D(g1, "x2") + h22 <- D(g2, "x2") + x1 <- x[1] + x2 <- x[2] + f <- eval(f) + g <- c(eval(g1), eval(g2)) + B <- rbind(c(eval(h11), eval(h12)), c(eval(h12), eval(h22))) + list(value = f, gradient = g, hessian = B) + } > > library(trust) > > tout <- trust(objfun, c(0, 0), 1, 5, blather = TRUE) > tout $value [1] -30.93159 $gradient [1] 0.000000e+00 -5.329071e-15 $hessian [,1] [,2] [1,] 2.616708 0 [2,] 0.000000 4 $argument [1] -2.266988 -7.071068 $converged [1] TRUE $iterations [1] 8 $argpath [,1] [,2] [1,] 0.000000 0.000000 [2,] -1.000000 0.000000 [3,] -1.718447 -1.866503 [4,] -2.001409 -5.856479 [5,] -2.274119 -7.594949 [6,] -2.266994 -7.120719 [7,] -2.266988 -7.071582 [8,] -2.266988 -7.071068 $argtry [,1] [,2] [1,] -1.000000 0.000000 [2,] -1.718447 -1.866503 [3,] -2.001409 -5.856479 [4,] -2.274119 -7.594949 [5,] -2.266994 -7.120719 [6,] -2.266988 -7.071582 [7,] -2.266988 -7.071068 [8,] -2.266988 -7.071068 $steptype [1] "hard-easy" "hard-hard" "easy-easy" "Newton" "Newton" "Newton" [7] "Newton" "Newton" $accept [1] TRUE TRUE TRUE TRUE TRUE TRUE TRUE TRUE $r [1] 1 2 4 4 4 4 4 4 $rho [1] 0.9975000 0.9725735 0.7278016 0.5975543 1.0576207 1.0068411 1.0000727 [8] 0.5634280 $valpath [1] 0.000000 -3.990000 -8.914432 -28.375535 -30.341199 -30.926623 -30.931588 [8] -30.931588 $valtry [1] -3.990000 -8.914432 -28.375535 -30.341199 -30.926623 -30.931588 -30.931588 [8] -30.931588 $preddiff [1] -4.000000e+00 -5.063301e+00 -2.673957e+01 -3.289515e+00 -5.535295e-01 [6] -4.930875e-03 -5.294725e-07 -6.305533e-15 $stepnorm [1] 1.000000e+00 2.000000e+00 3.999996e+00 1.759730e+00 4.742834e-01 [6] 4.913654e-02 5.144691e-04 5.614950e-08 > > (tout$stepnorm / tout$r)[tout$accept & tout$steptype != "Newton"] [1] 1.0000000 1.0000000 0.9999991 > > > proc.time() user system elapsed 0.17 0.06 0.17