I want to minimize a function f
with NMinimize
but an error occurs that says:
f[l_] := (
kk = NDSolve[{y'[x] == 2*x + 3, y[l] == 0}, y, {x, 0, l}];
out = Evaluate[y[0] /. kk];
out[[1]])
NMinimize[{f[t], 0 <= t <= 10}, f, t]
During evaluation of In[18]:= NDSolve::ndsv: Cannot find starting value for the variable y. >>
During evaluation of In[18]:= ReplaceAll::reps: {NDSolve[{(y^[Prime])[x]==3+2 x,y[{t}]==0},y,{x,0,{t}}]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing. >>
During evaluation of In[18]:= NMinimize::argrx: NMinimize called with 3 arguments; 2 arguments are expected. >>
Out[18]= NMinimize[{y[0], 0 <= t <= 10}, f, t]
How can I fix the function f
to avoid this problem?
f[l_?NumericQ] := Module[{kk = First[NDSolve[{\[FormalY]'[x] == 2 x + 3, \[FormalY][l] == 0}, \[FormalY], {x, 0, l}]]}, \[FormalY][0] /. kk]
$\endgroup$