程序死循环是为什么?
N=4;
total = 1000000;
count = 0;
for e = 1:total
p1=2*[rand,rand]-1;
p2=2*[rand,rand]-1;
p3=2*[rand,rand]-1;
p4=2*[rand,rand]-1;
p=[p1;p2;p3;p4]
%一次让每个点去计算斜率
for i = 1:N
k = p(i,2) / p(i,1);
b = [];%保存截距的矩阵
%计算截距
for j = 1:N
if j==i
continue;
else
b = [b,p(j,2) - k*p(j,1)];
end
end
if (b(1)>=0&&b(2)>=0&&b(3)>=0)||(b(1)<=0&&b(2)<=0&&b(3)<=0)
count = count + 1;%如果成立后就跳出
break;
end
end
end
res = count/total;
disp(res);