How to get an equation for a cubic spline using the spline function?
39 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Gina DiCarlo
am 24 Okt. 2016
Kommentiert: Aissam
am 16 Dez. 2022
Say I have two sets of data, x and y, such that
x = [1,2,3,4,5] y = [6,7,8,9,10]
t = linspace(1,5,100) Finding the cubic spline using the function:
splineX = spline(x,y,t);
I have used the command to be able to plot function splineXbut I'm not sure how I can find the actual equation the spline function calculates
(I know that for this data it would simply be a straight line but I only used this to better articulate what I'm trying to find)
0 Kommentare
Akzeptierte Antwort
Joshua Long
am 26 Okt. 2016
When you pass in a third parameter, the "spline" function automatically evaluates the spline for those points using "ppval". If you only pass in two parameters, "spline" returns a struct representing the spline created. The coefficients for the piecewise polynomials can be extracted using the function "unmkpp".
>> x = [1,2,3,4,5];
>> y = [6,7,8,9,10];
>> pp = spline(x, y);
>> [~, coeffs] = unmkpp(pp);
Each row of "coeffs" has the coefficients for one of the piecewise polynomials at each break.
For example:
>> coeffs(1, :)
is
[0, 0, 1, 6]
representing the function "x + 6".
2 Kommentare
farouk messaoud
am 22 Okt. 2018
hey; I have data to fit by cubic B-spline; How can I get the piecewise equations of the curves and the knot vector? thank you sir
Aissam
am 16 Dez. 2022
>> coeffs(1, :)
[0, 0, 1, 6]
represents
(x-pp.breaks(1))+6=x+5
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Splines 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!