How to write the B-spline basis function?
Mostra commenti meno recenti
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.
Risposte (2)
Babak
il 30 Ago 2012
0 voti
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.
siddhesh mane
il 25 Mar 2017
0 voti
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 Commento
Rohitashya
il 16 Lug 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.
Categorie
Scopri di più su Spline Postprocessing in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!