I am trying to solve a parametrized ODE, and wanting to find the parameter that maximize the solution at a specific point.
For example, in the following code I am trying to solve the ODE $df/dz=t \cos(f)$ that is parametrized by $t$ and find the parameter $t$ that maximized the solution at $z=5$:
sol[t_?NumericQ] :=
First@NDSolve[{f'[z] == t Cos[f[z]], f[0] == 1}, {f}, {z, 0, 10}]
FindMaximum[f[5] /. sol[t], {t, 1}]
Execution of the code finds an answer, but with a bunch of error messages like
ReplaceAll: {sol[t]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing
Note that I have specified that the parameter t is a numerical value by t_?NumericQ above. This has been suggested as the solution to similar problems in this forum, e.g. in optimization problem with NDSolve, but it doesn't solve my issue.
Any help?
NDSolve? The actual problem is more complicated, and it will be the best to useNDSolvein that situation.... – dashmile May 09 '19 at 14:34NumericQwas the key again. – dashmile May 09 '19 at 19:12