0% found this document useful (0 votes)
27 views1 page

Basis Spline Program For Matlab:: Function

This Matlab function calculates B-spline basis functions of degree n on a knot vector t, evaluated at points x. It first validates the inputs and allocates x values if not provided. It then calls an auxiliary recursive function to calculate the basis functions according to the Cox-deBoor recursion formula, returning the result y.

Uploaded by

vishwajeet patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views1 page

Basis Spline Program For Matlab:: Function

This Matlab function calculates B-spline basis functions of degree n on a knot vector t, evaluated at points x. It first validates the inputs and allocates x values if not provided. It then calls an auxiliary recursive function to calculate the basis functions according to the Cox-deBoor recursion formula, returning the result y.

Uploaded by

vishwajeet patil
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Basis spline program for Matlab:

function [y,x] = bspline_basis(j,n,t,x)

validateattributes(j, {'numeric'},
{'nonnegative','integer','scalar'});
validateattributes(n, {'numeric'},
{'positive','integer','scalar'});
validateattributes(t, {'numeric'}, {'real','vector'});
assert(all( t(2:end)-t(1:end-1) >= 0 ), ...
'Knot vector values should be non decreasing.');
if nargin < 4
x = linspace(t(n), t(end-n+1), 100); % allocate points
uniformly
else
validateattributes(x, {'numeric'}, {'real','vector'});
end
assert(0 <= j && j < numel(t)-n, ...
'Invalid interval index j = %d, expected 0 =< j < %d (0 =< j
< numel(t)-n).', j, numel(t)-n);

y = bspline_basis_recurrence(j,n,t,x);

function y = bspline_basis_recurrence(j,n,t,x)

y = zeros(size(x));
if n > 1
b = bspline_basis(j,n-1,t,x);
dn = x - t(j+1);
dd = t(j+n) - t(j+1);
if dd ~= 0 % indeterminate forms 0/0 are deemed to be zero
y = y + b.*(dn./dd);
end
b = bspline_basis(j+1,n-1,t,x);
dn = t(j+n+1) - x;
dd = t(j+n+1) - t(j+1+1);
if dd ~= 0
y = y + b.*(dn./dd);
end
elseif t(j+2) < t(end) % treat last element of knot vector as a
special case
y(t(j+1) <= x & x <= t(j+2)) = 1;
else
y(t(j+1) <= x) = 1;
end

You might also like