How do you get the equations of shape-preserving fitting method automatically?
Show older comments
This is one of the fitting methods provided by matlab (Curve fitting tool). it is under Interpolant. The difficulty in this method is that it gives its fitting results as piece-wise function. I want it in the form of equation, How to get it automatically?
8 Comments
Zakarya Motea
on 27 Sep 2019
Zakarya Motea
on 27 Sep 2019
John D'Errico
on 28 Sep 2019
Edited: John D'Errico
on 28 Sep 2019
I showed you how to get the "equations", automatically. What you will do with them is beyond me though, or why you even want them.
However, if you want MATLAB to somehow intuit that the "curve" going through a list of points should be piecewise linear, instead of piecewise cubic, then keep hoping. You could write a code that will create a piecewise linear interpolant, of course.
The shape preserving curve fit is a C1 piecewise cubic. That is, it will be continuous and differentiable everywhere, but not twice differentiable in general.
Zakarya Motea
on 28 Sep 2019
Edited: Zakarya Motea
on 28 Sep 2019
John D'Errico
on 28 Sep 2019
I fail to see that it is computationally intensive in context of what you want to do, or why you think it is.
Yes, if you use the code I wrote to compute symbolic polynomials, then it will take some amount of time to run, simply because you will have a long list of polynomials to create. If there are hundreds or thousands of points in the curve, then there will be as many polynomial segments. Your choice to make, and made necessary by your decision to do the computation.
The simpel fact is, if you create a spline from MANY points, then you will have MANY polynomial functions to create. There is no single simple function you can write down.
If you are willing to work with the polynomials as simply a list of coefficients, then you can essentially go directly to that form, with no effort made at all. It is already stored in the struct as lists of coefficients. But that requires you now need to understand what a spline is, how it is stored, etc. So you can trade off computational complexity with knowledge. But you NEED that knowledge, otherwise you are stuck with computation.
As I've said several times, it seems to make little sense to compute these polynomials explicitly. But that is what you want, what you asked to do.
Zakarya Motea
on 30 Sep 2019
Accepted Answer
More Answers (1)
Thiago Henrique Gomes Lobato
on 27 Sep 2019
From the Curve fitting tool you can select fit -> save to workspace to get a structure of your fit. From that structure you can access the coefficients and breaks as follows (substitute fittedmodel for the name you saved your structure):
Coeffs = fittedmodel.p;
Breaks = fittedmodel.p.breaks;
Here you will have a set of 4 coefficients for each interval x1 given in the breaks that describe a equation as shown in the pchip matlab page https://de.mathworks.com/help/matlab/ref/pchip.html :
which means that for every interval you will have a different equation (make sure to check if matlab does any normalization on x, you can do this by just outputing the model alone as "fittedmodel" then enter in the command prompt). I'm not sure if this is what you wanted, but it is the closest you will get for the analytical representation of your fit function. If the goal is to have one general equation for your data I would advise another fit functions as, for example, a polynomial one.
Categories
Find more on Interpolation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!