现在我遇到这么一个头疼的问题:
在平面坐标系中,假设沿着x正方向依次有0.5, 1.5, 3.5, 7.5, 15.5, 31.5, 63.5. 现在假设以最后一个点为圆点,以r0 = 2.5为半径做一个圆。
假设沿着x轴正方向有一个长70,宽2倍r0的矩形。假设这个矩形内有若干点,点的密度为D0 = 1.5,那么点的数量其实就是D0*70*2*r0(也即,密度乘以面积A=70*2*r0)。
那么请问落在上述圆内的点的数量是多少呢?是不是等于pi*r0^2*D0=29.45?
但是我怎么模拟都是14.75左右。我非常奇怪。我使用了R和Matlab软件结果都一样。下边是Matlab程序。请高手指点迷津,谢谢!
w = 70;
r0 = 2.5;
D0 = 1.5;
% 找到错误了,下述代码应该改为: A = (2*w)*(2*r0);
A = w*(2*r0);
point_number = A*D0;
temp = 0.5;
for i=1:7
x_right(i) = temp;
temp = temp + 2^(i-1);
end
x = x_right;
y = zeros(length(x), 1)';
n_sim = 200;
q = 1;
for i=1:n_sim
i
x_point = - w + (2 * w) * rand(point_number, 1);
y_point = - r0 + (2 * r0) * rand(point_number, 1);
%plot(x_point, y_point,'ko')
counter = 0;
for j=1:length(x_point)
if x_point(j) >= x(q) - r0 & x_point(j) <= x(q) + r0 & y_point(j) >= y(q) - sin(acos(abs(x_point(j) - x(q))/r0))*r0 & y_point(j) <= y(q) + sin(acos(abs(x_point(j) - x(q))/r0))*r0
counter = counter + 1;
end
end
Number(i) = counter;
end
figure(1)
plot(x_point, y_point,'ko')
axis square
axis([x(q)-r0 x(q)+r0 y(q)-r0 y(q)+r0])
mean(Number)
k = 0;
s = 10000;
for theta = 0:(2*pi/s):(2*pi- 2*pi/s)
k = k + 1;
x_temp(k) = x(q) + cos(theta)*r0;
y_temp(k) = y(q) + sin(theta)*r0;
end
%%%% An example %%%%
figure(2)
plot(x_point, y_point,'ko')
hold on
plot(x(q), y(q), 'r+')
plot(x_temp, y_temp, '-')
axis([x(q)-r0 x(q)+r0 y(q)-r0 y(q)+r0])
axis square
hold off