How to write the B-spline basis function?
32 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
回答(2 个)
Babak
2012-8-30
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 个评论
Babak
2012-8-30
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.
siddhesh mane
2017-3-25
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 个评论
Rohitashya
2024-7-16
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Splines 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!