0
$\begingroup$

A simplified example looks like this. The basic idea is to maximize fHelper by adjusting \[Alpha] for each t, and then use the resulting f in a differential equation. In the real world application, however, the functions and differential equation are much more complicated.

fHelper[t_, u_] := t + u;
f[t_] := MinValue[{fHelper[t, u], u >= 0.15, u <= 1.5}, u];
solution = NDSolve[{g'[t] == f[t], g[0.03] == 0}, g, {t, 0, 0.03}];

The last line produces a series of errors, which seems to be related to unsuccessful evaluation of f.

NMinimize::nnum:
   The function value 0.211738 + t is not a number at {u} = {0.211738}.

NMinimize::nnum:
   The function value 0.211738 + t is not a number at {u} = {0.211738}.

NMinimize::nnum:
   The function value 0.211738 + t is not a number at {u} = {0.211738}.

General::stop: Further output of NMinimize::nnum
     will be suppressed during this calculation.

I have checked f to see if there is something wrong with it, but it behaves exactly like a normal pure function, and I have no idea why Mathematica is complaining.

In[4]:= f[0.01]

Out[4]= 0.16

In[5]:= f[0.02]

Out[5]= 0.17
$\endgroup$
1
$\begingroup$

How about this?

fHelper[t_, u_] := t + u;
f[t_] := MinValue[{fHelper[t, u], u >= 0.15, u <= 1.5}, u];
int = {#, f @@ #} & /@ Range[0, 0.03, 0.001] // Interpolation;
solution = g/.Flatten@NDSolve[{g'[t] == int[t], g[0.03] == 0}, g, {t, 0, 0.03}];
Plot[solution[t],{t,0,0.03}]

Mathematica graphics

$\endgroup$
1
$\begingroup$
fHelper[t_, u_] := t + u;
f[t_?NumericQ] := MinValue[{fHelper[t, u], u >= 0.15, u <= 1.5}, u];
solution = NDSolveValue[{g'[t] == f[t], g[0.03] == 0}, g, {t, 0, 0.03}];
Plot[solution[x], {x, 0, 0.03}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.