Finding Coefficients in Bspline is making a problem ?
1 次查看(过去 30 天)
显示 更早的评论
% Define the x array
N = 100; % Example N value, adjust as needed
x = linspace(0, 5, N + 2); % Example x values, adjust as needed
% Initialize the a array
a = zeros(1, N + 2);
% Compute the coefficients a_i
for i = 1:(N + 2)
product = 1;
for j = 1:(N + 2)
if j ~= i
product = product * (x(i) - x(j));
end
end
a(i) = 1 / product;
end
% Display the coefficients
disp('Coefficients a_i:');
disp(a);
This is my code but the values of this coefficient are coming in negative is my code right?THIS IS THE ACTUAL FORMULA TO SOLVE
0 个评论
回答(1 个)
sai charan sampara
2024-7-17
Hello Rohitasya,
The code you have written is accuarte for calculating the coeffecients.The following code achieves the same result as yours:
N = 100;
x = linspace(0, 5, N + 2);
b = zeros(1, N + 2);
for i=1:(N+2)
x_new=x(i)-x;
x_new(i)=1;
product=prod(x_new);
b(i)=1/product;
end
disp(b)
Since "x" is an array of increasing values,for any iteration "i", the values of "x_new" in index positions 1 to "i-1" will be posiitve, at "i" the value of "x_new" is 1 and for index "i+1" to "N+2" the values are negative. So when calculating the product you are esssentially taking the product of "i" positive numbers and "N+2-i" negative numbers. So for even values of "i" the product is positive and for odd values it is negative. Hence the array "a" in your case has alternate negative and positive values. The same is shown in the code below:
for i=1:(N+2)
x_new=x(i)-x;
x_new(i)=1;
product=prod(x_new);
b(i)=1/product;
if(i==25 ||i==26)
disp("Value of i: "+i)
x_new
disp("Number of negative terms: "+sum(x_new<0))
disp("Product of the terms: "+product)
end
end
If you are expecting the coefficients to be of different behaviour then it is purely based on the data "x".
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Splines 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!