Is there any mathematical method of curve fitting for cases when the modeling function is unknown (another degree of freedom for the form of the function)?

32 views (last 30 days)
I am searching for a method of modeling data were the type of function unknown is and creates yet another degree of freedom. To find is function type and parameters, best fit.

Answers (3)

John D'Errico
John D'Errico on 8 Oct 2022
Edited: John D'Errico on 8 Oct 2022
No. There is no magical method that will look at your curve, and decide what form it has, and then fit that form. And yes, that would take some magic. Well, an AI could do a reasonable job on it, IF it were sufficiently trained to recognize many different various forms. And even then, expect many problems. The code would need to be VERY well written.
There are essentially infinitely many possible curve types. And for any set of data, one can find any of infinnitely many curves that pass exactly through the data. So again, any such scheme must fail.
Better is often to use a fitting approach that employs a spline model. Yes, you can use higher order polynomial fits. The problem is, high order polynomials have all sorts of crappy behaviors. Consider this classicly nasty problem...
x = -6:6;
y = 1./(x.^2 + 1);
p12 = polyfit(x,y,12);
xpred = linspace(-6,6);
ypred = polyval(p12,xpred);
plot(x,y,'bo',xpred,ypred,'r-')
Again, that is a classicly bad curve to try to fit with a polynomial. But it is also an example of why you don't want to use high order polynomials. It is attributed to runge (yes, the very same Runge that you know from other places in numerical lmethds, I assume.)
Splines are often a good choice for fitting curves, where you don't know the general form. This is because they use only low order segments, and cubic polynomials are sufficiently flexible, but also limited in the possible curve shapes you can have. Cubic splines also have the argument going for them that they are a mathematical model of what shipwrights used to call splines to fit smooth curves through sets of points. This is where the name spline itself is derived.
spl = spline(x,y);
plot(x,y,'bo',xpred,fnval(spl,xpred),'r-')
Next, where even cubic splines have robems, you can slso use curves generated using tools like pchip or makima, which are modified quasi-spline fitts, that attempt to interpolate a curve, while maintaining the fundamental shape of that curve.
Or, you can use tools like my SML tools, as found on the file exchange, wheree you fit a curve based on certain shape primitives. So you can tell it to fit the best monotonic curve to some data.

Steven Lord
Steven Lord on 8 Oct 2022
Here's a set of points. Can you tell me the equation I'm thinking of that generated this data?
x = 1:6;
y = zeros(1, 6);
No, it's not "y = 0". Nice guess, though.
It could be "y = sin(pi*x)"
y2 = sinpi(x)
y2 = 1×6
0 0 0 0 0 0
Or "y = sin(2*pi*x)"
y3 = sinpi(2*x)
y3 = 1×6
0 0 0 0 0 0
Or y = (x-1)*(x-2)*(x-3)*(x-4)*(x-5)*(x-6). I'll show the expanded form of this equation using z as the variable so I can evaluate it at the x values I defined above.
syms z
f = expand((z-1)*(z-2)*(z-3)*(z-4)*(z-5)*(z-6))
f = 
y4 = subs(f, z, x)
y4 = 
Given only x and y, how can you tell which of those functions (or combinations of them) is "the correct one"?

Torsten
Torsten on 8 Oct 2022
No, there is no such method.
Often, physical considerations are a way to decide for a suitable model function.
If this is not possible, the graphical representation of the data can be advantageous to derive a function type.
If nothing helps, approximation and interpolation with standard ansatz functions (polynomial, trigonometric, exponential) is the way to go.
  1 Comment
Walter Roberson
Walter Roberson on 8 Oct 2022
Given any finite list of x y pairs, you can construct a polynomial that goes exactly through the points (to within round-off error.)
But that also means that given any finite set of points, and any other additional point, you can construct a new polynomial that goes through all of the existing points and through the additional point.
But there was infinite choice in the location of the additional point — which implies that there must be an infinite number of polynomials that pass through any given finite list of points.
When there is an infinite number of curves that pass through a given set of points, it follows that there cannot be any mathematical way of automatically determining the "right" model for the set of points.
So not only does MATLAB not provide such a function: such a function is mathematically impossible.

Sign in to comment.

Categories

Find more on Spline Postprocessing in Help Center and File Exchange

Products


Release

R2019b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!