I have to calculate the intersection volume of three cylinder(radius=3) each of which lie on x,y,z axis perpendicular to one another. I'm using a 5x5x5 cube
I can't use any of the more advanced matlab functions as we haven't been taught it yet.
I tried manipulating code for the area of a circle in a 2D square to fit my current problem.
Here's what I got:
N= 10000; % number of points generated
a = -5;b = 5;r=3;hits=0;x = a + (b-a).*rand(N,1);y = a + (b-a).*rand(N,1);z = a + (b-a).*rand(N,1);radiixy = sqrt(z.^2+y.^2);radiixz = sqrt(x.^2+z.^2);radiizy = sqrt(x.^2+y.^2);i = radiixy && radiixz && radiizy <= r;%count the hits
for j = 1:N hits=hits+i(j);endmisses = N-hits;disp('hits')disp(hits)disp('misses')disp(misses)plot(x(i),y(i), z(i),'.g');hold;plot(x(~i),y(~i),z(~i),'.r');xlabel('x');ylabel('y');zlabel('z');title('Intersection Volume');
ERROR: Operands to the and && operators must be convertible to logical scalar values
Best Answer