# [R] Re: Helps on "optimize"

Han Lai hlai at whsun1.wh.whoi.edu
Wed Oct 17 21:05:16 CEST 2001

```Sorry about my missing statement.  My r-code is to find F-value that maximizes fish yield.
N0=15.4185,M=0.3,t=t,days=days,wt=wt,st=st,st1=st1 in optimize statement is constants or
constant arrays.

Han Lai wrote:

> Hi,
>
> I am trying to write a r-code that maximizes fish yield, which is
> summing over a total of 11 months (t=c(1:11))  for one cohort.  My code
> looks like this:
>
> t <- c(1:11)
> days <- 30*t-15
> yt <- 6.6*exp(log(12.3/6.6)*(days-126.3)/(189.5-126.3))
> wt <- exp(log(0.250206)+2.14418*log(yt))
> v0 <- 4; v1 <- 14
> st <- (yt-v0)/(v1-v0); st[yt<=v0] <- 0; st[yt>=v1] <-1;
> st1 <- cumsum(st)
> yield <- function(F,N0,M,t,days,wt,st,st1) {
>        sum(wt*N0*exp(-(t-1)*M-F*st1)*(st*F/(M+st*F))*(1-exp(-M-st*F))) }
>
> optimize(yield,interval=c(0,3),max=T,N0=15.4185,M=0.3,t=t,days=days,wt=wt,st=st,st1=st1)
>
> Everything is o.k. untile the last one line, which gives the following
> error message.
>
> Error in sum(wt * N0 * exp(-(t - 1) * M - F * st1) * (st * F/(M + st *
> :
>         Argument "t" is missing, with no default
>
>
> Cheers!
> Han
> Han-Lin.Lai at noaa.gov

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```