How to write the B-spline basis function?

33 views (last 30 days)
jljl
jljl on 30 Aug 2012
Commented: Rohitashya on 16 Jul 2024
Hi All,
here I have a code which creates a B-spline basis function given:
j= interval index
n= order
t= knot vector
x= variable of basis function
if true
function [y,x] = bspline_basis(j,n,t,x)
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
else
y(:) = t(j+1) <= x & x <= t(j+2);
end
end
It works fine until I try to plot the uniform quadratic basis function. Which results in:
if true
x = [0:0.1:3];
y = bspline_basis(0,3,[0 1 2 3],x);
plot(x,y)
end
That doesn't look right at all as it should have a bell shape... Please advise what can be done or where the mistake it to correct it...
THANK YOU.

Answers (2)

Babak
Babak on 30 Aug 2012
Your function called, bspline_basis() calls a nested function called, bspline_basis_recurrence() and the nested function again calls the parent function bspline_basis().
You cannot do this because you are basically calling the same function inside itself which (in some cases) results in an infinite loop. In some other cases that you have an if loop inside your function which is not true, then you are breaking the infinite loop and getting an answer. Anyways I recommend you reformat your code.
  2 Comments
jljl
jljl on 30 Aug 2012
@Babak Thanks for the reply, how would you suggest I change the code, I didn't understand why "I can't do this".
Babak
Babak on 30 Aug 2012
I don't know what math you are trying to do. If you can post the math equations, of what you are trying to do you can get a better input.

Sign in to comment.


siddhesh mane
siddhesh mane on 25 Mar 2017
use the truncated power function to calculate b spline basis function. the degree of function is (m-1), where m is an order of the function.
  1 Comment
Rohitashya
Rohitashya on 16 Jul 2024
HI I have a doubt regarding this code is it possible to reach out through your e-mail.Also I have a doubt regarding my code.

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!