Trouble fitting ode45
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Have anyone find that fitting using optimization toolbox (lsqcurvefit, curvefit, etc) doesn't fit well with ode45 or the ode solvers in general? I have been playing with this for months, and I have came to a conclusion that the fitting from optimization toolbox cannot fit with ode solutions from ode library that matlab provided. I found that (maybe), the fitting can't fit is due to the variable step size (h) in the ode solver.
2 commentaires
Star Strider
le 17 Juin 2017
To correct for the variable step size, use the independent variable of your data as the ‘tspan’ argument to the ODE solver you are using. Also, experiment with different solvers. For example with a ‘stiff’ problem, use ode15s.
Réponses (3)
John D'Errico
le 18 Juin 2017
Fitting the solution of an ODE solver can be difficult, since the ODE solver is an adaptive method, with a tolerance on the result. That means there will be tiny variations in the results, to within that tolerance.
But the fitting tool must now differentiate the result. It does so by making tiny changes, and looking at the result. After all, a derivative is simply a limit of deltay/deltax, for small deltax. There is a problem in this. Remember, we said that we expect tiny, uncontrolled variations in y, within the convergence tolerance. But divide them by a tiny value of deltax, and they may now be highly significant. In fact, those tiny variations in y may actually dominate the Jacobian estimate.
This can be an issue with optimizations on top of other methods, such as numerical integration, rootfinders, etc. Essentially, anytime you layer different adaptive methods, I would want to take great care this is not an issue.
There may be other reasons for a fitting problem. Do we know that you have posed a reasonable model for this fit?
One big reason for curve fitting problems is often that the user has posed a model that has no chance of fitting the data they give to the fitting tool. A second reason for failure is a terribly poor choice of starting values for the parameters.
But we are given no clue as to what the problem is, only that you have had problems in fitting.
2 commentaires
Walter Roberson
le 18 Juin 2017
My experience with your system from your earlier question https://www.mathworks.com/matlabcentral/answers/344290-is-this-the-correct-optimization-tool-lsqcurvefit-multistart was that you were asking for high precision output for a calculation that tends to get stuck in local minima with some notable differences between the "basins of attraction". So you spend a lot of time figuring out precisely the best coefficient for an area where the function might be twice as large as the best value. That is a waste of time. You would be better off surveying multiple areas with lower precision on the calculations, looking for the basins of attraction, and then only narrowing in on the best few.
This has nothing to do with the variable step-size on the solver: your goal is global optimization but you are spinning around a lot in local optimization.
If you had reason to expect that a small change in parameters could lead to a big change in function value (which is the case for some problems), then you probably should not be using interp1 inside your ode, as that interp1 amounts to a guess about how the function behaves over that interval: an expectation of a large change in resulting function value is implicitly an admission that the data being interpolated over is unlikely to be well represented by a series of straight line segments. If you had a model of the underlying function of the data you are interpolating, you would probably be better off doing a series of taylor expansions to at least a couple of degrees and using those in a piecewise fashion. Perhaps you could even justify piecewise cubic spline (which would save some trouble as that kind of interpolation is built in.)
1 commentaire
Voir également
Catégories
En savoir plus sur Interpolation dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!