integral2 failing to calculate area of a square inside a circle?

1 次查看(过去 30 天)
Hello all,
I am integrating the area contained within a square and a circle using integral2. I use a circle centered at (0,0) with radius 2.75 and two squares with edge 0.5 (blue on image) and 1 (red on the image), whose bottom left corner lies on (0.5, 0.5). As the circle is larger than the squares, I would expect the result of the integral to be the areas of each square, 0.25 for the blue and 1 for the red. However, the output for the red one is 0.75. Am I missinterpretating the result?
Thanks in advance!
The image:
The code:
Zfun1 = @(x,y) double((x.^2 + y.^2) <= 2.75); % Circle function
integral2(Zfun1,0.5,1.5,0.5,1.5,'Method','iterated',...
'AbsTol',1e-5,'RelTol',1e-5) % Red square
integral2(Zfun1,0.5,1,0.5,1,'Method','iterated',...
'AbsTol',1e-5,'RelTol',1e-5) % Blue square
rectangle1 = [0.5 , 0.5; % Coordinates red square (for plotting)
0.5 , 1.5;
1.5 , 1.5;
1.5 , 0.5;
0.5 , 0.5];
rectangle2 = [0.5 , 0.5; % Coordinates blue square (for plotting)
0.5 , 1;
1 , 1;
1 , 0.5;
0.5 , 0.5];
figure
circle(0,0,2.75); % circle
hold on; grid on
plot(rectangle1(:,1),rectangle1(:,2),'-.r'); % red square
plot(rectangle2(:,1),rectangle2(:,2),'-.b'); % blue square
axis equal
xlim([-0.1 2.8])
ylim([-0.1 2.8])
function h = circle(x,y,r)
hold on
th = 0:pi/50:2*pi;
xunit = r * cos(th) + x;
yunit = r * sin(th) + y;
h = plot(xunit, yunit);
hold off
end

采纳的回答

Tarunbir Gambhir
Tarunbir Gambhir 2021-6-15
编辑:Tarunbir Gambhir 2021-6-15
Please correct the equation of the circular region in function 'Zfun1'. It should be of the form, x^2+y^2<=r^2.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Geometric Transformation and Image Registration 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by