Question: Maximization of a procedure based upon a numeric dsolve.


I can't understand how to use Optimization in Operator Form when the objective function relies upon the numerical solution of a parameterized ODE.

Here is a very simple example :

  • I have a differential system that can be solved only numerically (so do not focus on the system I give to reply that I could solve it formally, I know that and the example is notional)
  • This system contains free parameters (K and M in my example) and an event whose firing time T I want to capture. 
  • The goal is to find what is the maximum value of T when K and M both belong to bounded ranges.
     
  • In the example I implicitely assumed that the event is fired for any (K, M) in their admissible ranges: this is a quite restrictive assumption that I will manage later.
restart:
sys := { M*diff(x(t), t$2)=t-K*x(t), x(0)=0, D(x)(0)=0};
evs := [[x(t)-5, halt]];

sol := dsolve(sys, numeric, events=evs, parameters=[K, M]):
interface(warnlevel=0):

TV := proc(P)
  sol(parameters=P):
  sol(10):
  return sol(eventfired=[1])[];
end proc:

# verification
TV([1$2])
                   HFloat(4.152620782382694)

# what I'm interested in
ranges := P[1]=0.8..1.2, P[2]=0.8..1.2:
Optimization:-NLPSolve(TV, ranges);
Error, (in Optimization:-NLPSolve) unexpected parameters: P[1] = .8 .. 1.2, P[2] = .8 .. 1.2

# another way
cstr := {0.8 < P[1], 1.2 > P[1], 0.8 < P[2], 1.2 > P[2]}:
Optimization:-Maximize(TV, cstr);
Error, (in Optimization:-NLPSolve) constraints must be specified as a set or list of  procedures


optim_parametric_dsolve.mw


I'm using both Maple 2015 and Maple 2020 and would appreciate an answer which fits these two versions.
Could you help me solve this issue?

TIA

Please Wait...