From phlamber@luc.ac.be  Wed Nov 12 09:44:32 1997
From: phlamber@luc.ac.be (Philippe Lambert)
Date: Wed, 12 Nov 1997 10:44:32 +0100 (MET)
Subject: R-alpha: Optimize
Message-ID: <Pine.OSF.3.96.971112103643.2170A-100000@alpha>

The function optimize returns the opposite value of the objective
when maximizing:

> f <- function(x) -x**2+1
> optimize(f,c(-5,5),maximum=TRUE)
$maximum
[1] 0

$objective
[1] -1

> f(0)
[1] 1

What should be corrected:

> optimize
function (f, interval, lower = min(interval), upper = max(interval), 
        maximum = FALSE, tol = .Machine$double.eps^0.25, ...) 
{
        if (maximum) {
                val <- .Internal(fmin(function(arg) -f(arg, ...), 
                        lower, upper, tol))
                list(maximum = val, objective = -f(val,...)
                                               ^^^
SHOULD BE +f(val,...) <-------------------------|

   Philippe

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


R-alpha: Optimize
Philippe Lambert