This might be some simple mistake, but I am running out of ideas. I am trying to fit an ODE system to some data. This error keeps appearing
NDSolve::nlnum: "The function value {0.299812 - 0.000145006 a, 0.001 -0.000145006 a} is not a list of numbers with dimensions {2} at {t, sa[t], st[t]} = {0.000483352, 0.000145006, 1.}."
The code is adapted to How do I find the best parameter to fit my data if the model is a interpolating function? :
data = {
{0.`, 34.84229229652888`}, {3.7448333333333332`, 29.004820470134124`},
{7.4896666666666665`, 22.762395022844483`}, {11.2345`, 16.82225654209896`}
}
Clear[kss, kdm, at, gof];
kss = 0.001; kdm = 0; at = 0.3;
eqs[kas_, k2s_, at_] := {
st'[t] == kss - k2s sa[t] - kdm st[t],
sa'[t] == kas (at - sa[t]) (st[t] - sa[t]) - k2s sa[t],
sa[0] == 0, st[0] == 1
}
gof[kas_, k2s_, at_] :=
(
soltry = st /. NDSolve[eqs[kas, k2s, at], {st, sa}, {t, 0, 100}] // First;
(soltry /@ data[[All, 1]]) - data[[All, 2]]/data[[1, 2]] // #.# &
)
NMinimize[{gof[1, a, 0.3], 0 < a < 5}, a]
NMinimize[f[x],...]
, the evaluation off[x]
should (in the present context) be delayed by using the pattern_?NumberQ
in the definition of f (f[x_?NumberQ]:=...
shall be used instead off[x_]:=...
). This problem is already explain somewhere on stack exchange. – andre 29 mins ago $\endgroup$