% Demo3
% From this script we conclude:

% (a) The points arrange themselves along an ellipse that has tilt 45
%     degrees.
% (b) Sometimes the major axis is along the 45 degree line. Sometimes
%     it is along the 135 degree line
% (c) The points seem to "move" along the ellipse.

  for n=10:10:40
     nSmoothings = 10*n;
     for eg=1:3
        x = randn(n,1); x = x-sum(x)/n; x = x/norm(x);
        y = randn(n,1); y = y-sum(y)/n; y = y/norm(y);
        ShowPBetter(x,y,nSmoothings,1)
     end
  end
  
% To understand this, we need to learn more about
% the vectors 
%               cVec = cos((0:n-1)*(2pi/n))' 
%               sVec = sin((0:n-1)*(2pi/n))'
%
% since the x and y vectors are moving to their span.

   clc
   disp('    n     cTc     sTs      cTs      sum(cVec)    sum(sVec)')
   disp('-----------------------------------------------------------')
   for n = 5:5:50
       [cVec,sVec] =  csVecs(n);
       cTc = cVec'*cVec;
       sTs = sVec'*sVec;
       cTs = cVec'*sVec;
       fprintf('%5d  %6.2f  %6.2f  %10.2e  %10.2e   %10.2e\n',n,cTc,sTs,cTs,sum(cVec),sum(sVec))
   end
   
% Conclusion: cVec'cVec = sVec'sVec = n/2,  and sum(cVec) = sum(sVec) = cVec'sVec = 0

% Let's look at what the vectors M^k*cVec and M^k*sVec look like...

   n = 8;
   [cVec,sVec] = csVecs(n);
   c = cVec/norm(cVec);
   s = sVec/norm(sVec);
   format short
   McMatrix = c;
   MsMatrix = s;
   for k=1:5
       c = Mprod(Mprod(c)); c = c/norm(c); McMatrix = [McMatrix c];
       s = Mprod(Mprod(s)); s = s/norm(s); MsMatrix = [MsMatrix s];
   end
   McMatrix = McMatrix
   MsMatrix = MsMatrix
   
% Observe that M*M*c is a multiple of S*c (an "upshift")
% Observe that M*M*s is a multiple of S*s (an "upshift")

% This explains how the vertices "move" around the ellipse.
% After many smoothings,

%         x =  alfa1*cVec + beta1*sVec + very small other stuff
%         y =  alfa2*cVec + beta2*sVec + very small other stuff

% After 2 more iterations...

%         x =  alfa1*S*cVec + beta1*S*sVec + very small other stuff
%         y =  alfa2*S*cVec + beta2*S*sVec + very small other stuff

% The vertices have been shifted

       

   