How to write the B-spline basis function?
    16 ビュー (過去 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 で Spline Postprocessing についてさらに検索
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



