:::::::::::::: circle.m :::::::::::::: clear; hold off; t=linspace(0,pi/2,101); x=sin(t); y=cos(t); x(102)=0; y(102)=0; fill(x,y,'r') pause; x_r=rand(1,100); y_r=rand(1,100); hold on; plot(x_r,y_r,'.') num_in=sum(x_r.^2+y_r.^2<1) Pie=num_in*4/100 pause; hold off; fill(x,y,'r') x_r=rand(1,1000); y_r=rand(1,1000); hold on; plot(x_r,y_r,'.') num_in=sum(x_r.^2+y_r.^2<1) Pie=num_in*4/1000 :::::::::::::: mmempty.m :::::::::::::: function d=mmempty(a,b) % function returns a, unless a is empty. Then it % returns b. if isempty(a) d=b; else d=a; end; :::::::::::::: vswap.m :::::::::::::: function vswap(X,Y) % Tries to swap values of x and y % DOES NOT WORK!!! if(nargin~=2) error('Two input arguments required') end tmp=X; X-Y; Y=tmp; :::::::::::::: mdist.m :::::::::::::: function d=mdist(x,y) % Returns the shortest distance between any two points. % Want to find all pairs. d=99999999; [rx,cx]=size(x); [ry,cy]=size(y); if(nargin~=2) error('mdist needs two arguments') end if(rx~=ry || rx~=1 || cx~=cy) error('Arrays in mdist must have one row and be of the same size') end for i=1:cx for j=1:cy if(i~=j) tmp=local_dist(x(i),y(i),x(j),y(j)); d=min([tmp d]); end end end % end mdist function d=local_dist(x1,y1,x2,y2) d=sqrt((x1-x2).^2+(y1-y2).^2); % end of subfunction.