2

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*)
Sos
  • 2,168
  • 16
  • 31
  • First of all, if C, D, and E are your real functions, you'll experience conflicts with the built-in symbols of the same names. Other than that, ParametricNDSolveValue is giving you a 5-dimensional ParametricFunction solution, 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:01
  • C, D and E were just used in here to replace the real names of the variables. – Sos Jan 17 '13 at 15:44
  • Syntax issue? I assume you are not really putting "[Model]" in there. But I'm guessing you have model[kestim][t] and I don't think model[kestim] is returning something in the form you would require. – Daniel Lichtblau Jan 17 '13 at 15:55
  • @DanielLichtblau where I wrote "[Model]" I have the model equations. I also edited the post with some new information. Thanks again for all the help guys – Sos Jan 18 '13 at 17:31
  • 1
    Probably best to post complete code. As it stands there are too many ways something can go wrong for people to sensibly speculate (unless they are much more familiar with this kind of problem than I am). – Daniel Lichtblau Jan 18 '13 at 17:42
  • 1
    Could you try f[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. If NDSolve chokes you could specify DependentVariables->{G,T,H,Y,U} –  Jan 20 '13 at 08:43
  • @ruebenko, thanks! I am looking into that! – Sos Jan 23 '13 at 11:25
  • 1
    @Sosi, did you solve this problem already? – Cendo Aug 07 '13 at 15:42
  • 1
    @Cendo I had followed ruebenko's suggestions, but it didn't solve the problem. Indeed, DanielLichtblau was right and the problem was pinned with the model. I provided a full example of the solution in the thread – Sos Aug 08 '13 at 10:56
  • 1
    Also, I am sorry to everyone for the delay in posting this answer. I eventually had to work on something else and only now was reminded of this thread by @Cendo. Thanks for all the input! – Sos Aug 08 '13 at 10:57
  • 1
    I, too, am interested in any progress on this. I noticed in chat on 1/16 @OleksandrR. linked to this excellent example (which actually does what I've pieced together previously, wish I had found), and shortly afterwards pointed out complications with general systems with more parameters than datasets. Fitting a system suspected to be determined in large part by the dataset of one variable, it sounded like you had something going there. Will keep sniffing about... – Ghersic Aug 11 '13 at 18:55
  • 2
    Just to note that the link @Ghersic mentions is to a notebook with basically the same content as my answer here. I had written this for my own purposes before I had reason to use it in an answer. – Oleksandr R. Aug 23 '13 at 13:43

0 Answers0