红针表示针与平行线相交,蓝针表示针没有与平行线想交 a行间距 b针长 % Buffon's Needle is one of the oldest problems in the field of geometrical probability. clear,clc,close all %绘制坐标系 n = 5;%线数目 a = 2;%线间距 x = ones(n+1,1)* ; y = (0:n)'* ; hold on for i = 1:n+1 & ...
用MATLAB近似计算e,利用《高等数学》中Taylor知识可得 clear,clc s = 1; n = 0; eps = 1e-6; % 误差控制 % 阶乘n!用prod(1:n)表示 while (3/prod(1:(n+1)))eps n = n+1; s = s + 1/prod(1:n); end fprintf('达到精度需要的项数 %d n ',n) fprintf('近 ...