%add_ex1
X = [1 2 5 -2 -1];
Y = [9 6 -3 5 7];
numpoints = 5;
refx = 0; refy = 0;
%loop over all x,y points to find the one closest to (0,0)
mindist = 999;
maxdist = -9999;
avgdist = 0;
for i=1:numpoints
xd = X(i)-refx;
yd = Y(i)-refy;
dist = sqrt(xd*xd + yd*yd);
avgdist = avgdist+dist;
if (dist < mindist)
mindist = dist;
end
if (dist > maxdist)
maxdist = dist;
end
end
mindist
maxdist
avgdist = avgdist/numpoints;
avgdist