favouriteMatrix = [1,2,3;4,5,6;7,8,9] % define a matrix det(favouriteMatrix) % determinant of that matrix rand(3) % creates a 3x3 matrix of randomly distributed numbers on (0,1) help rand % open help file for rand help randi % open help file for randi James = randi([1,10],50,50); % we now have a 50x50 matrix called James, who contains random integers % between 1 and 10 E = eig(James) % eigenvalues of James (outputs a list, which we have labelled E) figure % create figure plot(real(E),imag(E),'bo') % plot eigenvalues of James on the complex plane, using stylish blue % circles % i.e. plot real component against imaginary component of each item in E p=0.3; q=1-p; % define transition rates A = [0,p,q;q,0,p;p,q,0]; % create 3x3 stochastic transition matrix (with periodic boundaries) eig(A) % eigenvalues! figure % create new figure plot(real(eig(A)),imag(eig(A)),'bo') % plot those eigenvalues hold on % hold the plot! ang = [0:0.01:2*pi]; %create list of values between 0 and 2*pi in increments of 0.01 plot(0+1.*cos(ang),0+1.*sin(ang),'r') % parametric plot of a circle radius 1, centered on (0,0) % plotted as a fashionable red line A A^2 A^3 A^4 A^5 A^10 A^100 % iterate the matrix and watch what happens to it's entries % what does this tell you? [V,E] = eig(A') % obtain the eigenvectors and eigenvalues of A % N.B. the transpose is necessary to obtain the LEFT eigenvectors % we aren't interested in RIGHT eigenvectors r = 0.1; p=0.2;q=1-p-r; % define new transition rates A = [r,p,0,q;q,r,p,0;0,q,r,p;p,0,q,r] % create 'lazy' random walk transition matrix A^2 A^10 A^100 % iterate the matrix... figure %create new figure plot(real(eig(A)),imag(eig(A)),'bo') % plot eigenvalues of A (blue circles) hold on; plot(0.1+0.9.*cos(ang),0.9.*sin(ang),'r') % plot radius 0.9 circle centered on (0.1,0) plot(real(eig(A^10)),imag(eig(A^10)),'go') % plot eigenvalues of A^10 (green circles) % visualisation of Gershgorin Theorem