How to write the B-spline basis function?

조회 수: 33 (최근 30일)
jljl
jljl 2012년 8월 30일
댓글: Rohitashya 2024년 7월 16일
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.

답변 (2개)

Babak
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
jljl
jljl 2012년 8월 30일
@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 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
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
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 CenterFile Exchange에서 Splines에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by