用R,將三個點的座標精確到小數點後10位,透過100000次模擬,形成銳角三角形的機率大概為0.2376;形成鈍角三角形的機率大概為0.7241。f=function(n){ m=10 z=99 x=round(runif(6,0,1),m) a1=(x[1]-x[3])*(x[1]-x[3])+(x[2]-x[4])*(x[2]-x[4]) a2=(x[1]-x[5])*(x[1]-x[5])+(x[2]-x[6])*(x[2]-x[6]) a3=(x[5]-x[3])*(x[5]-x[3])+(x[6]-x[4])*(x[6]-x[4]) y=sort(c(a1,a2,a3)) if(y[1]+y[2]>y[3]){ z=0 }else{ z=2 } z}mm=100000x=sapply(c(1:mm), f)length(x[x==0])/mm把問題拓展到1*1*1的正方體中,形成銳角三角形的機率大概為0.45984;形成鈍角三角形的機率大概為0.54366。f=function(n){ m=10 z=99 x=round(runif(9,0,1),m) a1=(x[1]-x[4])*(x[1]-x[4])+(x[2]-x[5])*(x[2]-x[5])+(x[3]-x[6])*(x[3]-x[6]) a2=(x[1]-x[7])*(x[1]-x[7])+(x[2]-x[8])*(x[2]-x[8])+(x[3]-x[9])*(x[3]-x[9]) a3=(x[4]-x[7])*(x[4]-x[7])+(x[5]-x[8])*(x[5]-x[8])+(x[6]-x[9])*(x[6]-x[9]) y=sort(c(a1,a2,a3)) if(y[1]+y[2]<y[3]){ z=0 }else{ z=2 } z}mm=100000x=sapply(c(1:mm), f)length(x[x==0])/mm
用R,將三個點的座標精確到小數點後10位,透過100000次模擬,形成銳角三角形的機率大概為0.2376;形成鈍角三角形的機率大概為0.7241。f=function(n){ m=10 z=99 x=round(runif(6,0,1),m) a1=(x[1]-x[3])*(x[1]-x[3])+(x[2]-x[4])*(x[2]-x[4]) a2=(x[1]-x[5])*(x[1]-x[5])+(x[2]-x[6])*(x[2]-x[6]) a3=(x[5]-x[3])*(x[5]-x[3])+(x[6]-x[4])*(x[6]-x[4]) y=sort(c(a1,a2,a3)) if(y[1]+y[2]>y[3]){ z=0 }else{ z=2 } z}mm=100000x=sapply(c(1:mm), f)length(x[x==0])/mm把問題拓展到1*1*1的正方體中,形成銳角三角形的機率大概為0.45984;形成鈍角三角形的機率大概為0.54366。f=function(n){ m=10 z=99 x=round(runif(9,0,1),m) a1=(x[1]-x[4])*(x[1]-x[4])+(x[2]-x[5])*(x[2]-x[5])+(x[3]-x[6])*(x[3]-x[6]) a2=(x[1]-x[7])*(x[1]-x[7])+(x[2]-x[8])*(x[2]-x[8])+(x[3]-x[9])*(x[3]-x[9]) a3=(x[4]-x[7])*(x[4]-x[7])+(x[5]-x[8])*(x[5]-x[8])+(x[6]-x[9])*(x[6]-x[9]) y=sort(c(a1,a2,a3)) if(y[1]+y[2]<y[3]){ z=0 }else{ z=2 } z}mm=100000x=sapply(c(1:mm), f)length(x[x==0])/mm