[R] Relatively Simple Maximization Using Optim Doesnt Optimize
Abby Spurdle
@purd|e@@ @end|ng |rom gm@||@com
Fri Mar 13 04:52:48 CET 2020
> L= 1006.536
> L= 1006.537
> L= 1006.535
> It appears to have chosen step size 0.001, not 0.00001. It should be
> getting adequate accuracy in both 1st and 2nd derivatives.
> Those little ripples you see in the plot are not relevant.
I'm impressed.
But you're still wrong.
Try this:
---------
#not good R code!
v = numeric ()
production3 <- function(L){
#store in vector
v <<- c (v, L)
budget=100000
Lcost=12
Kcost=15
K=(budget-L*Lcost)/Kcost
machines=0.05*L^(2/3)*K^(1/3)
return(machines)
}
optim.sol <- optim (1001, production3 ,method="CG", control = list(fnscale=-1) )
n = length (v)
print (n)
plot (1:n ,v, type="l")
---------
After 401 iterations (on my computer), the algorithm hasn't converged.
And I note it's converging extremely slowly, so I don't see any
argument for increasing the number of iterations.
And try this:
(The first 30 steps).
---------
plot (1:30 ,v [1:30], type="l")
---------
Little ripples aren't going anywhere...
More information about the R-help
mailing list