Tell me more ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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: I edited the post to make it simpler with some new information that I have.

share|improve this question
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 at 14:01
C, D and E were just used in here to replace the real names of the variables. – Sosi Jan 17 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 at 15:55
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 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} – ruebenko Jan 20 at 8:43
show 2 more comments

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.