B - Spline Surface Fitting on a gridded data
28 views (last 30 days)
Show older comments
Hello everyone. I'm new on the topic of Spline interpolation. My problem is:
- I have a x vector containing the value of the grid along the x direction.
- I have a y vector containing the value of the grid along the y direction. This vector could have a different legth with respect to the x vector (Rectangular grid)
- I have a z(x,y) matrix containing the data on this grid.
I would like to fit the z(x,y) surface using Multivariante B-splines with a certain knots along x and y directions (knotsx,knotsy) and a certain degree of the spline along x and y directions (k_degree_x k_degree_y). From a simple research the Matlab function to use is:
spap2({knorl1,...,knorlm},k,{x1,...,xm},y)
and, in my case:
sp=spap2({knotsx,knotsy},[k_degree_x k_degree_y],{x,y},z)
Is it right? Am I missing something so far?
For now in my code I still let aptknt to decide the knots of the spline.
Here there is the complete code based on a simple function that I'm trying to fit:
x = linspace(-2,2,100);
y = linspace(-5,5,500);
k_degree_x=4;
k_degree_y=4;
knots_mult_x=3;
knots_mult_y=3;
x_knot = aptknt(x,knots_mult_x); % returns a knot sequence suitable for interpolation at the data sites tau by splines of order k.
y_knot = aptknt(y,knots_mult_x);
[xx, yy] = meshgrid(x,y);
z = exp(-(xx.^2+yy.^2));
figure
surf(x,y,z);
figure
sp=spap2({x_knot,y_knot},[k_degree_x k_degree_y],{x,y},z');
fnplt(sp);
What I want to have as Output is the coefficient matrix of the B-spline function that i think is sp.coefs. From the Mathematical formulation that I found online about B-splines this matrix should have the dimension: k_degree_x+knotsx+1 x k_degree_y+knotsy+1.
where g and h are the length of the knots vectors in, respectively, x and y direction and k and l are, respectively, the degree of the splines in x and y direction.
My question is: Why from Matlab output i retrive a sp.coefs having the dimension of the input grid? In my case length(x)=500 X length(y)=100?
Can you send me some documentation, if you have, about what is implemented in Matlab with spap2?
Thank you in advance,
Davide
0 Comments
Answers (0)
See Also
Categories
Find more on Spline Construction 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!