Message Boards Message Boards

0
|
5067 Views
|
3 Replies
|
1 Total Likes
View groups...
Share
Share this post:

Fitting Data to the Sum of some Solutions of an ODE System

Posted 9 years ago

Hello all,

I have a system consisting of 4 ODEs, which I call sys (incl. initial conditions). The parameters are called par1, par2, par3. My data consists of a time series of measurements (from time 0 to 100), which represents the sum of the last two solutions (sol3, sol4) of the ODE system. For fitting the model to this kind of data, I did the following:

(* Numerical solution *)
model[par1_, par2_, par3_] := model [par1, par2, par3] = Module[{nsol, sol1, sol2, sol3, sol4, t},
nsol = NDSolveValue[{sys}, {sol1, sol2, sol3, sol4},{t,0,100}, MaxSteps->10000];
Return[nsol];
]

(* Relevant solution part *)
modeldata[par1_?NumericQ, par2_?NumericQ, par3_?NumericQ] := Total[Through[Part[model[par1, par2, par3], 3:4][t]]];

(* Fitting *)
nlm=NonlinearModelFit[data, modeldata[par1, par2, par3], {par1, par2, par3}, t, Method->"NMinimize"];

Problem: Mathematica complains about the Interpolating Function: Input value lies outside the range of data in the interpolating function. Extrapolation will be used.

I really do not see where the problem lies. Indeed, the data range should be covered by the InterpolatingFunction since the integration covers the relevant range.

Thanks for any advice.

POSTED BY: marc123
3 Replies

It's hard to debug this without the code, but first, as a general suggestion, try rewriting it using ParametricNDSolve.

http://reference.wolfram.com/language/ref/ParametricNDSolve.html

There are some examples at the bottom of that page on optimizing parameter values. They might be helpful if you haven't already seen them.

So, modeldata[...] appears to be an Interpolating function and it is complaining that it is being given a t value out of its range. What are the t values in data? That is, what are the values of data[[All,1]]? What happens when you run modeldata[...] on every one of them with some reasonable value for the parameters? I get the feeling that one of them is outside the range of modeldata[...]. I don't know if the range of modeldata[...] depends on it's parameters or not.

POSTED BY: Sean Clarke
Posted 9 years ago

Hello Sean,

many thanks for your reply.

The problem appears also when using ParametricNDSolve.

It seems to me that the integration stops at a time point within the range of the data points, which is from 31 to 44.

ParametricNDSolve::mxst: Maximum number of 10000 steps reached at the point t$265 == 40.30493527608063`. >> InterpolatingFunction::dmval: Input value {40.726} lies outside the range of data in the interpolating function. Extrapolation will be used. >>

However, several attempts to fix this problem, e.g., by increasing the maximum number of steps, failed.

It might certainly be that the problems are due to the nature of the equations, which possess terms of the form

1/(1+((sol3[t]+sol4[t])/(sol1[t]+sol3[t]+n))^j)bsol3[t]/(sol1[t]+sol3[t])(sol1[t]+sol3[t]-sol2[t]-sol4[t]+n)+(1-1/(1+((sol3[t]+sol4[t])/(sol1[t]+sol2[t]+n))^j))csol4[t]/(sol2[t]+sol4[t])(sol1[t]+sol3[t]-sol2[t]-sol4[t]+n)

My observation is that for smaller values for the exponent j, the integration more and more succeeds. However (for some reasons) the exponent j should not be that small. In addition, the occurrence of the problem depends on how many parameters (and which one) are to be fixed.

Moreover, how reliable are the fitting results if the numerical integration ends at a certain time point and extrapolation is used (as described above)? I'm asking since if it does not matter, then one may simply ignore the error messages...

Any suggestions how I can deal with these problems? Thanks in advance!

POSTED BY: marc123

That error message isn't uncommon. Especially if you search online for "NDSolve::mxst". It basically just means the function is hard to numerically integrate beyond some point. There's no simple, general solution for that. There are many different techniques that can be done depending on the nature of the equations.

Off the top of my head, here's what I normally try:

  • Try out many different possible values for the "Method" option. Maybe you'll get lucky and one of them will work.
  • Look at the equation. Can it be related to a simpler set of equations somehow?
  • Plug the results back into the original equations and see how well they satisfy them. It might be possible to show that it was sol 1, 2, 3, or 4 that was really causing the problem. Maybe it's changing values very quickly or becoming highly oscillatory.
  • Read through the list of available "Method" options again and see which seem to address the problem I'm seeing.
  • Reduce and simplify the equations to get the simplest version of them that produces the problem. This will help other people advise you on how to solve it numerically at very least.
  • Try to find a solvable approximation of the equation.

I'd really first bombard the problem with many different numerical methods. One of my favorites that I always try is (Method -> "StiffnessSwitching").

POSTED BY: Sean Clarke
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract