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((1 / 10) * 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) > ## IGNORE_RDIFF_BEGIN > tout $value [1] -25.0025 $gradient [1] -3.803178e-18 -5.861978e-14 $hessian [,1] [,2] [1,] 2.0003 0 [2,] 0.0000 4 $argument [1] -0.0499975 -7.0710678 $converged [1] TRUE $iterations [1] 6 $argpath [,1] [,2] [1,] 0.00000000 0.0000000 [2,] -0.02500000 -0.9996875 [3,] -0.03528824 -2.9996875 [4,] -0.04237731 -6.9996875 [5,] -0.04999766 -7.0721747 [6,] -0.04999750 -7.0710681 $argtry [,1] [,2] [1,] -0.02500000 -0.9996875 [2,] -0.03528824 -2.9996875 [3,] -0.04237731 -6.9996875 [4,] -0.04999766 -7.0721747 [5,] -0.04999750 -7.0710681 [6,] -0.04999750 -7.0710678 $steptype [1] "hard-hard" "easy-easy" "easy-easy" "Newton" "Newton" "Newton" $accept [1] TRUE TRUE TRUE TRUE TRUE TRUE $r [1] 1 2 4 4 4 4 $rho [1] 0.9900250 0.9375080 0.6213427 0.9895692 1.0001565 0.9998752 $valpath [1] 0.0000000 -0.9912625 -8.1907459 -24.9923542 -25.0024975 -25.0024999 $valtry [1] -0.9912625 -8.1907459 -24.9923542 -25.0024975 -25.0024999 -25.0024999 $preddiff [1] -1.001250e+00 -7.679383e+00 -2.704081e+01 -1.025025e-02 -2.450566e-06 [6] -1.350200e-13 $stepnorm [1] 1.000000e+00 2.000026e+00 4.000006e+00 7.288674e-02 1.106665e-03 [6] 2.598268e-07 > ## IGNORE_RDIFF_END > > (tout$stepnorm / tout$r)[tout$accept & tout$steptype != "Newton"] [1] 1.000000 1.000013 1.000002 > > > > proc.time() user system elapsed 0.12 0.07 0.18