[R] Relatively Simple Maximization Using Optim Doesnt Optimize

Jeff Newmiller jdnewm|| @end|ng |rom dcn@d@v|@@c@@u@
Thu Mar 12 15:03:43 CET 2020

The help file points out that CG is "fragile" ... and I would expect that failing to define a gradient function will exacerbate that.

I think you should use a different algorithm or specify a gradient function. You might also consider working with the more recent optimr package contributed by Dr Nash, author of the original optim function in R.

On March 12, 2020 2:30:26 AM PDT, Skyler Saleebyan <skylerbsaleebyan using gmail.com> wrote:
>I am trying to familiarize myself with optim() with a relatively simple
>L and K are two terms which are constrained to add up to a total 100000
>(with respective weights to each). To map this constraint I plugged K
>the function (to make this as simple as possible.)
>Together these two feed into one nonlinear function which is the
>product of
>two monotonic (on the positive interval) functions. Then that numbers
>returned in a function fed to optim, which should maximize the output
>adjusting L. The whole code is:
>production1 <- function(L){
>  budget=100000
>  Lcost=12
>  Kcost=15
>  K=(budget-L*Lcost)/Kcost
>  machines=0.05*L^(2/3)*K^(1/3)
>  return(machines)
># production1(6000) #example of number with much higher output vs optim
>[1] 1006.536
>[1] 90.54671
>function gradient
>     201      101
>[1] 1
>For some reason this never explores the problem space and just spits
>some answer close to the initial condition. What am I doing wrong?
>Skyler S.
>	[[alternative HTML version deleted]]
>R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
>PLEASE do read the posting guide
>and provide commented, minimal, self-contained, reproducible code.

Sent from my phone. Please excuse my brevity.

More information about the R-help mailing list