%% Distribution of Eigenvalues in Complex Plane
% This example plots the distribution of eigenvalues from a sample of 20,000 random circulant matrices of size 18-by-18 in the complex plane. The matrix elements are uniformly sampled from the set {–0.4,0.4}.
% Create an array E of size 18-by-20,000 to store eigenvalues.

E = zeros(18,20000);

% Set the random number generator to the default value. Iterate the following operations 20,000 times in a for-loop statement:
% Create a 1-by-18 row vector x with random elements of either –0.4 or 0.4.
% Use the vector x as an input to create a random circulant matrix A.
% Find the eigenvalues of A and store them in E.

rng('default')
for i = 1:20000
  x = -0.4 + 0.8*randi([0 1],1,18);
  A = gallery('circul',x);
  E(:,i) = eig(A);
end

% Create a scatter plot to display the eigenvalues E in the complex plane. Set the x- and y-axis limits to range from –3 to 3.

scatter(real(E(:)),imag(E(:)),'b.')
xlabel('Re(E)')
ylabel('Im(E)')
xlim([-3 3])
ylim([-3 3])
axis square

%
% Copyright 2019 The MathWorks, Inc.