How can I obtain the analytical expression (polynomial) of the spline curve from a curve fitting?

I have extracted data from some graphs (images) and then I curve fitted that data to obtain some spline curves. What I need is the polynomial of those spline, the f(x) that draw the initial graphs, the function that relates the x and y points. How can I do that? Thanks!

 Accepted Answer

Hi Radu,
x = 1:10;
y = sin(x).^3;
a = interp1(x,y,'spline','pp')
a =
struct with fields:
form: 'pp'
breaks: [1 2 3 4 5 6 7 8 9 10]
coefs: [9×4 double]
pieces: 9
order: 4
dim: 1
orient: 'first'
>> a.coefs
ans =
0.3050 -1.3676 1.2186 0.5958
0.3050 -0.4525 -0.6016 0.7518
-0.3075 0.4626 -0.5914 0.0028
0.6000 -0.4598 -0.5886 -0.4335
-0.7723 1.3403 0.2920 -0.8818
0.6265 -0.9767 0.6556 -0.0218
-0.7998 0.9029 0.5818 0.2836
0.6101 -1.4966 -0.0119 0.9684
0.6101 0.3337 -1.1748 0.0700
each row is a polynomial in standard Matlab notation, coefficient of x^3 first, coefficient of x^0 last.
a = spline(x,y) does the same thing.

3 Comments

Hi, thanks a lot for your answer, it is exactly what I asked for. The problem is that I probably didn't ask for exactly what I wanted and don't know how to manage the information you have provided. This might be one of those "don't expect people to make your work" type of questions but anyway, I don't exactly know what to do with those polynomials, I have somewhere around 40 of them. Is this like a piecewise function where each of the polynomials describes my spline for a given little range? Is my f(x) described by polynomials bit by bit? Is there any matlab way to use those polynomials so that if I give an X value a function or something gives back the associated y=f(x) value back for the entire spline? Or do I have to know the exact range that each polynomial describes so that I can create a big piecewise expression that gives me f(x)?
Hi, I think I found it. I think using ppval I can find the f(x) value for a given x in the entire spline. Correct me if I'm wrong please.
Hello Radu,
Yes, each polynomial describes the function for a given little range. Also each polynomial is local in the sense that x = 0 effectively restarts at the beginning of each range. And you are correct, ppval will reconstruct the whole works.

Sign in to comment.

More Answers (1)

What I need is the polynomial of those spline
A spline consists of many polynomials stuck together, not just one.Also, there are a number of different forms in which spline fits can exist in Matlab, and we don't know which ones you have. If you really need to break down a spline, and it is in the form of a pp structure you could use unmkpp. More likely, you used cftool, in which case you have a cfit object.
Regardless, there is a reason that Matlab doesn't provide you with an analytical form for the spline. It's because far better tools are provided to post-process a fit,

1 Comment

Hi, thank you for your answer, but as I am a big matlab noob I could understand David Goodmanson's answer better.

Sign in to comment.

Categories

Community Treasure Hunt

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

Start Hunting!