Generate a mathematical funciton from a graph or raw data?
20 次查看(过去 30 天)
显示 更早的评论
I m used to using mathematical functions however if I want to describe raw data as a mathematical function I m not really sure where to begin. So, for example I know data is linear if y = x and I know its cubic if y = x^3 but is it possible for matlab to use a general function to detect what kind of mathematical function the raw data describes? And based on the description of the funcions described I want to be able to dynamically detect this and change the behaviour of the program based on this.
0 个评论
回答(1 个)
the cyclist
2015-11-19
I appreciate that this seems like a thing that one would want to do. But it is not. Here is a small part of the reason why.
Suppose that you have N = 2 data points. Easy enough! Fit a line. Perfect fit. Done.
Now suppose you have N = 3 data points. Still pretty easy! Fit a parabola (i.e. a 2nd order polynomial). Perfect fit again. I'm so good at this!
N = 4 points ... Fit a cubic, the 3rd-order polynomial. Perfect fit. Wow! (Do you see where I am going with this?)
Arbitrary N points ... Fit an (N-1)th order polynomial. Perfect fit!
The trouble, as I hope you might realize, is that that perfect-fitting polynomial probably has little or no relationship to the underlying process that generated those data, because it is fitting the noise as well as the signal. It is "overfitting".
And, notice, I have only used polynomial fitting here. There are zillions of other functional forms that could also have given perfect fits.
It's a fool's errand to try what you suggest.
3 个评论
Stephen23
2015-11-19
编辑:Stephen23
2015-11-19
What the cyclist states is perfectly correct, but there is also the special case of where you have some prior knowledge of the system, and can therefore limit the system to some known set of functions. This might work if you have measurements of a simple physical phenomenon, for example. In practice this would mean non-linear curve fitting, a fit metric and some selection criteria.
John D'Errico
2015-11-19
The problem is, in order to use a nonlinear model, you need to have some model in mind. There is no intelligent, automatic way to just pick the overall nonlinear form that would represent your data. Ok, there are computer programs that will fit every model from a complete stable of models, then pick the one with the "best" fit. I have no good feeling towards those schemes. Sorry, but no.
If you have no intelligent choice of model, then it is very often better to use a spline model, such as my SLM toolbox . It allows you to build in your own knowledge about the process into the model, like if it should be a monotonic function.
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!