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) { + ##### Rosenbrock's function ##### + stopifnot(is.numeric(x)) + stopifnot(length(x) == 2) + f <- expression(100 * (x2 - x1^2)^2 + (1 - x1)^2) + 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(3, 1), 1, 5, blather = TRUE) > tout $value [1] 5.160801e-15 $gradient [1] 5.430221e-07 -2.003744e-07 $hessian [,1] [,2] [1,] 802.0001 -400 [2,] -400.0000 200 $argument [1] 1 1 $converged [1] TRUE $iterations [1] 21 $argpath [,1] [,2] [1,] 3.000000 1.000000 [2,] 2.213163 1.617161 [3,] 1.995363 3.605266 [4,] 1.982307 3.929371 [5,] 1.982307 3.929371 [6,] 1.982307 3.929371 [7,] 1.920608 3.687103 [8,] 1.793795 3.203451 [9,] 1.587591 2.477924 [10,] 1.525765 2.324137 [11,] 1.525765 2.324137 [12,] 1.446444 2.087048 [13,] 1.281393 1.615071 [14,] 1.237286 1.528931 [15,] 1.237286 1.528931 [16,] 1.189572 1.413397 [17,] 1.092024 1.183211 [18,] 1.059858 1.122264 [19,] 1.010263 1.018171 [20,] 1.003384 1.006732 [21,] 1.000032 1.000052 $argtry [,1] [,2] [1,] 2.213163 1.6171606 [2,] 1.995363 3.6052660 [3,] 1.982307 3.9293710 [4,] 1.032382 0.1634548 [5,] 1.737285 2.9598532 [6,] 1.920608 3.6871035 [7,] 1.793795 3.2034513 [8,] 1.587591 2.4779236 [9,] 1.525765 2.3241367 [10,] 1.227793 1.4186882 [11,] 1.446444 2.0870482 [12,] 1.281393 1.6150706 [13,] 1.237286 1.5289305 [14,] 1.066466 1.1081695 [15,] 1.189572 1.4133965 [16,] 1.092024 1.1832113 [17,] 1.059858 1.1222640 [18,] 1.010263 1.0181710 [19,] 1.003384 1.0067320 [20,] 1.000032 1.0000522 [21,] 1.000000 1.0000001 $steptype [1] "easy-easy" "easy-easy" "Newton" "Newton" "easy-easy" "easy-easy" [7] "easy-easy" "Newton" "Newton" "Newton" "easy-easy" "easy-easy" [13] "Newton" "Newton" "easy-easy" "easy-easy" "Newton" "Newton" [19] "Newton" "Newton" "Newton" $accept [1] TRUE TRUE TRUE FALSE FALSE TRUE TRUE TRUE TRUE FALSE TRUE TRUE [13] TRUE FALSE TRUE TRUE TRUE TRUE TRUE TRUE TRUE $r [1] 1.000 2.000 4.000 4.000 1.000 0.250 0.500 1.000 1.000 1.000 0.250 0.500 [13] 0.500 0.500 0.125 0.250 0.500 0.500 0.500 0.500 0.500 $rho [1] 1.1323840 1.0268439 1.0009051 -86.2278968 0.1941958 1.0028937 [7] 0.9305907 0.6758818 1.1429810 -3.5561846 1.0310304 0.5325419 [13] 1.1190080 -0.8036577 1.0321407 0.7780458 1.1565171 0.9687805 [19] 1.0341229 1.0081017 1.0001652 $valpath [1] 6.404000e+03 1.077921e+03 1.514382e+01 9.649301e-01 9.649301e-01 [6] 9.649301e-01 8.477839e-01 6.504098e-01 5.260586e-01 2.778900e-01 [11] 2.778900e-01 2.019671e-01 1.515350e-01 5.668301e-02 5.668301e-02 [16] 3.622117e-02 1.712582e-02 3.690009e-03 7.103242e-04 1.167477e-05 [21] 1.363381e-08 $valtry [1] 1.077921e+03 1.514382e+01 9.649301e-01 8.142600e+01 8.835630e-01 [6] 8.477839e-01 6.504098e-01 5.260586e-01 2.778900e-01 8.402095e-01 [11] 2.019671e-01 1.515350e-01 5.668301e-02 8.956198e-02 3.622117e-02 [16] 1.712582e-02 3.690009e-03 7.103242e-04 1.167477e-05 1.363381e-08 [21] 5.160801e-15 $preddiff [1] -4.703421e+03 -1.034994e+03 -1.416607e+01 -9.331211e-01 -4.189951e-01 [6] -1.168082e-01 -2.120955e-01 -1.839836e-01 -2.171240e-01 -1.581244e-01 [11] -7.363787e-02 -9.470083e-02 -8.476432e-02 -4.091166e-02 -1.982466e-02 [16] -2.454271e-02 -1.161748e-02 -3.075707e-03 -6.755962e-04 -1.156742e-05 [21] -1.363155e-08 $stepnorm [1] 1.000000e+00 2.000000e+00 3.243678e-01 3.883875e+00 1.000000e+00 [6] 2.500007e-01 5.000010e-01 7.542615e-01 1.657492e-01 9.532179e-01 [11] 2.500056e-01 5.000045e-01 9.677608e-02 4.541137e-01 1.249989e-01 [16] 2.500017e-01 6.891465e-02 1.153040e-01 1.334802e-02 7.473704e-03 [21] 6.093529e-05 > > (tout$stepnorm / tout$r)[tout$accept & tout$steptype != "Newton"] [1] 1.0000000 1.0000000 1.0000030 1.0000019 1.0000224 1.0000091 0.9999912 [8] 1.0000067 > > > proc.time() user system elapsed 0.10 0.09 0.18