看下面的程序
构建一个数组(列向量)
令t =该向量对t进行操作,相当于进行了循环
hold on是将前面的图保留继续在上面画图hold off下一个图不在之前的图上面画
function nn=ex
n=10000;r=randn(n,1);t=rand(n,1)pi2;x=r.cos(t);y=r.sin(t);plot(x,y,'g’)x0=0;y0=1;r0=0.5;hold on;plotcircle(x0,y0,r0);hold off;figure(gcf)dx=x-x0;dy=y-y0;d=sqrt(dx.dx+dy.dy);nn=sum(d<r0);axis equalfunction plotcircle(x0,y0,r)t=0:0.01:pi2;x=x0+rcos(t);y=y0+rsin(t);plot(x,y,‘r’);