I have been trying to find the value for the parameter kestim that yields the best fit of a model to some data points. datac has 25 data points, but I illustrate with just a few. I tried to do the fitting after using ParametricNDSolveValue:
datac={{0,73},{300,605},{600,1244},{900,1874},{1200,2000},{1500,2900},{1800,3300}};
pfun = ParametricNDSolveValue[{
[MODEL]
} /. parameters,
{G,T,H,Y,U},
{t, 0, 7200}, {kestim}]
(*because variable Y is the one I am interested, I specify it in the next command*)
f[x_]:=pfun[x][[4]]
(*I evaluate `f[1.1][600]` I get the correct value of variable `Y`. I then fit it to the data.*)
fit = NonlinearModelFit[datac, f[kestim][t], {kestim}, {t}]
Yet, I get the error Part::partw: "Part 4 of \!\(\*TagBox[RowBox[{\"ParametricFunction\" [etc etc] does not exist.>> and the output FittedModel[InterpolatingFunction[{{0.,7200.}},<>][t]]. From the latter I am able to extract the value of kestim, although the value obtained for this parameter is not significant.
I know I am not providing enough information, but I really cannot show my model here. Yet, do you think you could help me find what I am doing wrong? Thank you so much!
Edit: What was going wrong was probably the ReplaceAll inside pfun. Now it is working. I provide a draft version of the model below:
pfun = ParametricNDSolveValue[{
G'[t] == 50 - 6*^3 T[t] G[t], G[0] == 0,
T'[t] == 73 H[t] - 11 T[t], T[0] == 25000,
H'[t] == ke (1 - T[t] - H[t]) - 73 H[t], H[0] == 0
},
{G,T,H},
{t, 0, 7200}, {ke}];
(*as per suggestion of @ruebenko*)
f[ke_?NumericQ] := pfun[ke][[3]]
f[1.1][600]
(*Out=0.0135135*)
C,D, andEare your real functions, you'll experience conflicts with the built-in symbols of the same names. Other than that,ParametricNDSolveValueis giving you a 5-dimensionalParametricFunctionsolution, which does not correspond to your one-dimensional dataset. It might be better to resolve this in chat? – Oleksandr R. Jan 17 '13 at 14:01f[x_?NumericQ]:=....and see what happens. Also, you could use{Y}- no need to give the entirelist of dependent variables if you just need one. IfNDSolvechokes you could specifyDependentVariables->{G,T,H,Y,U}– Jan 20 '13 at 08:43