1
$\begingroup$

In the code I wrote there is a ParametricNDSolve with four parameters. I want to minimize an error function with Minimize. If I consider ParametricNDSolve with just one parameter everything works, and Minimize takes nearly 114 s to evaluate. but if I enter other parameters and modify the code to take them into account, NMinimize stops working and continues to evaluate for an unspecified time without giving any results. I tried to change the Method, but nothing changes. Is it possible to get an idea of what the reasons are?

Do[errfunc[x_?NumberQ,y_?NumberQ][a][b]:=Sum[(f[x,y][a][b][tobs[[i]]]-fobs[[i]])^2,{i,1,20}],{a,1,2},{b,5000,5100,100}]
Table[{a,b,NMinimize[{errfunc[x,y][a][b],{1950<x<1952},{y>0}},{x,y}][[1]]},{a,1,2},{b,5000,5100,100}]

f[x,y] is a result from parametricNDSolve, tobs and fobs are observed quantities.

$\endgroup$
2
  • 2
    $\begingroup$ This is not the oracle of Delphi, if you want a reasonable answer, try to give some minimal code that shows the problem you have. $\endgroup$ – Daniel Huber Oct 8 '20 at 15:22
  • $\begingroup$ It is silly to define loads and loads of functions for every single a,b. Instead define a single function that takes those as parameters: errfunc[x_?NumberQ, y_?NumberQ, a_, b_] := Total[MapThread[(f[x, y][a][b][#1] - #2)^2 &, {tobs, fobs}]]; Table[{ a, b, First[NMinimize[{errfunc[x, y, a, b], 1950 < x < 1952, y > 0}, {x, y}]] }, {a, 1, 2}, {b, 5000, 5100, 100}] $\endgroup$ – flinty Oct 8 '20 at 16:06

Your Answer

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

Browse other questions tagged or ask your own question.