How can I find the output functions while using cubic spline interpolation?

5 Ansichten (letzte 30 Tage)
Hello, My name is ReV.
I have a set of data on the X,Y plane and use the matlab "interp1 - cubic" to interpolate a few points within the X range.
The thing is I want matlab to display the function of each spline in the console. For example: I have 6 sets of points. Now I need to find the functions of 5 individual splines which is solved by matlab.
Could anyone help me, please?
Best regards, ReV.

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 10 Mai 2015
Call spline() to get the piecewise polynomial. You can use unmkpp() to extract information about the piecewise polynomials.
  2 Kommentare
ReVl Hulk
ReVl Hulk am 10 Mai 2015
Bearbeitet: ReVl Hulk am 10 Mai 2015
Thank you Mr. Roberson,
I used spline() and unmkpp() to extract the spline information successfully.
But when I used the extracted information and reconstruct the plots, it doesn't seem right.
I don't understand how the coefs are arranged in the output matrix. In details from the following picture, the first spline is correct, but the remainings are strange. (I also attached my .m file)
For example: if matlab returns: coefs = a b c d
Then my spline function is: a*x^3 + b*x^2 + c*x + d
Is that the correct arrangement?
Best regards,
ReV.
ReVl Hulk
ReVl Hulk am 10 Mai 2015
Ok, I found out the arrangement.
Everything works just fine now.
Thank you Mr.Roberson!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

John D'Errico
John D'Errico am 10 Mai 2015
I missed this question before, so I'll add some information to what Walter has given.
Splines in a pp form use what I like to call a relative form. Each segment is assumed to live on the interval [0,b(i+1) - b(i)], where b is the vector of breaks.
This relative form is important, both to understand, as well as to know why it is used. Suppose we had an interval between breaks that was [1e7,1e7+1]. You don't want to form the cube of those numbers to evaluate the spline over that segment, since double precision computations have only roughly 16 digits in terms of dynamic range. Instead, by forcing the spline segment to live on [0,1] here, those evaluations become now well posed.
I provide a tool in my SLM toolbox that can take apart a spline into its individual segments.
x = 0:.2:1;
y = sin(pi*x);
pp = spline(x,y);
funs = slmpar(pp,'symrel');
Now, lets look at the actual polynomials that are generated on each interval.
vpa(funs(2,1),5)
ans =
- 3.4689*u^3 - 0.72507*u^2 + 3.2227*u
vpa(funs(2,2),5)
ans =
- 3.4689*u^3 - 2.8064*u^2 + 2.5164*u + 0.58779
vpa(funs(2,3),5)
ans =
- 8.8818e-15*u^3 - 4.8878*u^2 + 0.97756*u + 0.95106
vpa(funs(2,4),5)
ans =
3.4689*u^3 - 4.8878*u^2 - 0.97756*u + 0.95106
vpa(funs(2,5),5)
ans =
3.4689*u^3 - 2.8064*u^2 - 2.5164*u + 0.58779
Those were the relative polynomials. So they each live on an interval of [0,0.2] (Since the breaks were equally spaced.)
pp.breaks
ans =
0 0.2 0.4 0.6 0.8 1
Be careful not to try to evaluate ay of these polynomials at x=0.5 or something like that, since they live on this restricted interval.

Kategorien

Mehr zu Spline Construction finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by