# Using MinValue with NDSolve

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:= f[0.01]

Out= 0.16

In:= f[0.02]

Out= 0.17


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}] 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}] 