111
代码说明:
function pi = solve2(count,m,cc) 借助布冯投针实验 仿真求pi的值 pi=0 frq=0 randNo = binornd(1,cc,1,m) pro=zeros(1,count) for j=1:count for i = 1:m if randNo(1,i) == 1 frq = frq + 1 end pro(i) = frq/i end pi = (2*m)/frq pro(j) = pi end pro = pro,num =1:count plot(num,pro) (function pi = solve2 (count, m, cc) to vote with Buffon needle experiment simulation find the value of pi pi = 0 frq = 0 randNo = binornd (1, cc, 1, m) pro = zeros (1, count) for j = 1: count for i = 1: m if randNo (1, i) == 1 frq = frq+ 1 end pro (i) = frq/i end pi = (2* m )/frq pro (j) = pi end pro = pro, num = 1: count plot (num, pro) )
下载说明:请别用迅雷下载,失败请重下,重下不扣分!