The error of using command "integral"
Show older comments
I am trying to integrate a function , but the result is wrong. The strange thing is, if I integrate from -5 to 5, it is correct (0.0117). If I integrate it from -15 to 5, it will wrong (get 0). And then, if I integrate it from -15 to -5, the result is still 0.... I don't know where does matlab steal my 0.0117.............
The test code:
theta=4;
SP=@(X,D) univariate2dirboxspline_fast(cos(theta/180*pi),sin(theta/180*pi),X,D);
P2=0.394147314513724;
P3=1.391711364773548;
integral(@(X)SP(X,P2).*SP(X,P3),-5,5) % from -5 to 5 is 0.0117
integral(@(X)SP(X,P2).*SP(X,P3),-15,5) % from -15 to 5 is 0
integral(@(X)SP(X,P2).*SP(X,P3),-15,-5) % from -15 to -5 is 0
Related function, it can create a 2 dimension box spline, where D is the shifting value
function v = univariate2dirboxspline_fast(xi1, xi2, x,d)
%% Expects xi1, xi2, and x to be row vectors
xi = [xi1; xi2];
xi(abs(xi)<sin(1/180*pi))=0;
% x = abs(x - sum(xi)/2); % Symmetrize around 0
x=x-d;
x = abs(x);
l1 = vecnorm(xi, 1);
v = (l1/2-x) ./ abs(prod(xi));
h = 1 ./ vecnorm(xi, Inf);
v = max(v, 0);
v = min(v, h);
%v = piecewise(v > 0, v, 0);
%v = piecewise(v > h, h, v);
end
Accepted Answer
More Answers (0)
Categories
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!