R Under development (unstable) (2026-02-10 r89394 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. > require(BB) Loading required package: BB > > # from projectLinear.Rd > > fn <- function(x) (x[1] - 3/2)^2 + (x[2] - 1/8)^4 > > gr <- function(x) c(2 * (x[1] - 3/2) , 4 * (x[2] - 1/8)^3) > > Amat <- matrix(c(1, -1, 1, 1, -1, 1, -1, -1), 4, 2, byrow=TRUE) > b <- c(-1, -1, -1, -1) > meq <- 0 # all 4 conditions are inequalities > > p0 <- c( -0.3599199, -1.2219309) > > r1 <- spg(par=p0, fn=fn, gr=gr, project="projectLinear", + projectArgs=list(A=Amat, b=b, meq=meq)) iter: 0 f-value: 6.750707 pgrad: 1.78621 > > if(any(1e-14 < r1$par - c(1,0))) stop("projectLinear test 1 failed.") > > > meq <- 1 # first condition is now an equality > r2 <- spg(par=p0, fn=fn, gr=gr, project="projectLinear", + projectArgs=list(A=Amat, b=b, meq=meq)) iter: 0 f-value: 6.750707 pgrad: 1 > > if(any(1e-14 < r2$par - c(0,1))) stop("projectLinear test 2 failed.") > > # box-constraints > > Amat <- matrix(c(1, 0, 0, 1, -1, 0, 0, -1), 4, 2, byrow=TRUE) > b <- c(0, 0, -0.5, -0.5) > > r3 <- spg(par=p0, fn=fn, gr=gr, project="projectLinear", + projectArgs=list(A=Amat, b=b, meq=0)) iter: 0 f-value: 6.750707 pgrad: 0.5 iter: 10 f-value: 1 pgrad: 4.446537e-06 > > if(any(1e-14 < r3$par - c(0.5, 0.1146409327454269)) + ) stop("projectLinear test 3 failed.") > > > proc.time() user system elapsed 0.12 0.07 0.18