# [S] Problem with the OPTIMIZE function

Marianne Maehle-Schmidt (mms@matematik.su.se)
Thu, 19 Nov 1998 17:59:16 +0100 (CET)

Hi!

I have a problem with the 'optimize' function in S-plus
(Version 3.4 Release 1 for Sun SPARC, SunOS 5.3 : 1996).
I have two functions that I want to optimize over the
interval (0,150):

my.fcn<-function(x){
(exp(-exp(6.09-.08*x)) - exp(-exp(10-.13*x)))
}

my.fcn2<-function(x){
(exp(-exp(6.09-.2*x)) * (1-exp(-exp(10-.25*x))))
}

However it seems, that the algorithm forgets to check some
of the interval.

Consider the interval (0,y).

1) In the my.fcn case it seems that
if y>z*1.618034
where z is the point where my.fcn(z)=0 then the algorithm
forgets to check the interval (y/2.618034,y).

y/2.618034 is the first point chosen by the algorithm,
y/1.618034 is the second.

2) In the my.fcn2 case it seems that
if y>maximum*2.618034
where maximum is the maximum of my.fcn2 that I am looking
for then the algorithm forgets to check (0,y/2.618034).

Can this be right? Or have I misunderstood something?
Any suggestions? - PLEASE!!

Below is the code I have used for optimizing.

Sincerely,
marianne

#OPTIMIZE PROBLEM:

my.fcn<-function(x){
(exp(-exp(6.09-.08*x)) - exp(-exp(10-.13*x)))
}

my.fcn2<-function(x){
(exp(-exp(6.09-.2*x)) * (1-exp(-exp(10-.25*x))))
}

D<-seq(0,150)

par(mfrow=c(1,2))
plot(D,my.fcn(D),type="l",lty=1,ylim=c(0,1),ylab = "")
plot(D,my.fcn2(D),type="l",lty=2,ylim=c(0,1),ylab = "")

optimize(my.fcn,c(0,150),maximum=T,keep.xy=T)
optimize(my.fcn2,c(0,150),maximum=T,keep.xy=T)

#my.fcn
uniroot(my.fcn,c(0,150))\$root*1.618034 #=69.53456
optimize(my.fcn,c(0,127),maximum=T,keep.xy=T)
optimize(my.fcn,c(0,126),maximum=T,keep.xy=T)
my.fcn(69.53456) #the 'real' maximum
my.fcn(69)
my.fcn(70)

#my.fcn2
36.49266*2.618034 #=95.53902
optimize(my.fcn2,c(0,96),maximum=T,keep.xy=T)
optimize(my.fcn2,c(0,95),maximum=T,keep.xy=T)
my.fcn2(36.49266) #the 'real' maximim
my.fcn2(36)
my.fcn2(37)

+----------------------------------------------------------------------+
| |
|Marianne Mæhle-Schmidt E-mail: mms@matematik.su.se |
|Mathematical Statistics Phone: +46 8 16 4556 (matstat) |
|Stockholm University +46 8 517 76416 (radfys) |
|S - 106 91 Stockholm Fax: +46 8 612 67 17 (matstat) |
|Sweden +46 8 34 35 25 (radfys) |
| |
| URL: http://www.matematik.su.se/matstat/biostat/ |