# B-Spline least squares (spap2)

9 views (last 30 days)
JC on 10 Jun 2014
Answered: Unai San Miguel on 29 Sep 2016
Hello,
I am trying to construct a B-spline equation to fit some data points. I am rather new to B-splines, even though I had done some work previously on simple cubic splines. What I am really struggling with is how spap2 gives me so few coefficients. For example, spap2(3,4,x,y) only gives me 6 coefficients when I expect 3*4 = 12 coefficients. How can I construct 3 piece wise cubic equations with only 6 coefficients? What form should it be?
As an aside,it would be great if someone can provide a reference to a good tutorial or reference guide on the Internet on in text for B-splines. I am currently reading de Boor's tutorial ("a practical guide to splines") and find too much emphasis on the derivation rather than practical usages, despite its appealing title.
Thanks!

Unai San Miguel on 29 Sep 2016
Hi,
spap2 returns the B-form of the spline, and if you don't supply a knot vector it will use C2 continuity (k-2 = 4-2 in your example) in the breaks.
The coefficients you were expecting are those of the pp-form of the spline, the coefficients of the power basis of the polynomials which form the spline. But because of the continuity conditions the 12 coefficients are not independent, there are 3 * 2 constraints, which give you only 6 independent coefficients (in the B- basis).
You can do fn2fm(spap2(3, 4, x, y), 'pp') to see the (3,4)-array of coefficients you were expecting.
Regarding the information on splines, the documentation in the Splines part of Curve Fitting Toolbox is a good companion to PGS. The notes in this link are useful, but the summations start in 0, not in 1, and that is a bit confusing (for me).

### Categories

Find more on Spline Postprocessing 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!