This question is related to a previous question and answer here:
NMinimize or NMaximize for a dynamic problem
but tackles a different problem.
I am trying to solve a simple linear quadratic optimal depletion problem.
Choose $q(t)$ from $t=0$ to $ T$ so as to maximize the objective when $R(t+1)=R(t)-q(t).$
My code is here:
T = 100; p = 1.; δ = 0.05127; ρ = 1./(1. + δ); c = 50.; R0 = 1.;
obj[qlist_ /; VectorQ[qlist, NumericQ]] :=
Module[{Rlist, obj},
Rlist = FoldList[(#1 - #2) &, R0, qlist];
If[Min[Rlist] < 0, Return[-1000]]; (* Constraint to keep R(t)>=0 for all t *)
(* This is the objective function *)
Sum[ρ^t*(p*qlist[[t + 1]] -
0.5 c ((qlist[[t + 1]])^2)/Rlist[[t + 1]]), {t, 0, T - 1}]
]
choicevar = Table[Unique[q], {i, 0, T - 1}];
sol = NMaximize[Prepend[Thread[0 <= choicevar], obj[choicevar]],
choicevar];
sol[[1]]
I have an analytical solution to this class of problems and this code works perfectly when $R0=100$.
But for $R0=1$ as above, it fails.
The problem also wont solve if I set $T=250$ and $R0=100$.
The failures are of two kinds.
1) failures to converge to desired accuracy, or
2) violation of the constraint $(R(t)=>0)$, Returning a solution -1000.
The problems that will not solve all seem to have solutions (in the later periods) where q gets close to zero (the real solution may be or order 10^-3, for instance) so I suspect the issue has to do with accuracy or precision but I tried variations and allowing up to 10000 iterations and it does not work.
Can anyone please help me unlock the power of NMaximize?
At this point, Excel Solver seems to be a better solution but I refuse to believe that! Thanks.



obj[RandomVariate[UniformDistribution[{0, 0.010}], T]]this returns positive value. – Xminer May 23 '19 at 01:37Thread[0 <= choicevar]is equivalent toRt => 0. Consequently, many inputs are permitted that yieldobj[] == -1000. If a numerical solver sees a lot of such results, it will decide it has found the maximum. – Michael E2 May 23 '19 at 19:02Min[Rlist] < 0with a penalty, which I took to be "the constraint (Rt=>0)" mentioned in the question; however, there is no such constraint "Rt=>0" mentioned elsewhere, esp. just what the definition of "Rt" is. Perhaps you meant R(t) >= 0, but again there is no definition of R(t), although it is mentioned earlier. -- In short, the question needs clarification. I know how to answer the question I thought you were asking, but it's unclear to me what you are actually asking. – Michael E2 May 24 '19 at 02:05