function HotSpotsAny(n,a,b,c,e) %n = # rows; a,b,c = edge weights; e = the eigenvalue considered (e=2 for %Fiedler vector, e=1 returns the constant vector) N=n^2; %N = #verticies A=zeros(N,N); for k=0:n-1; %we go through the rows (labeled 0 to (n-1) for simpler mathematical expressions) for l=1:k, j=k^2+2*l; %we go across the row picking our the center nodes of "downward pointing T's" A(j,j)=A(j,j)-a-b-c; %the rest adds an "a edge" to the left of j, a "b edge" to the right of j, and a "c edge" below j A(j-1,j-1)=A(j-1,j-1)-a; A(j+1,j+1)=A(j+1,j+1)-b; A(j-2*k,j-2*k)=A(j-2*k,j-2*k)-c; A(j-1,j)=A(j-1,j)+a; A(j,j-1)=A(j,j-1)+a; A(j+1,j)=A(j+1,j)+b; A(j,j+1)=A(j,j+1)+b; A(j-2*k,j)=A(j-2*k,j)+c; A(j,j-2*k)=A(j,j-2*k)+c; end end [V,D]=eigs(A,e,0.001); %Grabs the e eigenvalues/vectors with eigenvalue closest to 0.001 (0 messes up the code for some reason). v=V(:,e) %We set v to be the e-th eigenvector. if v(1)>0; %For consistancy we multiply by -1 if neccesary to ensure the bottom vertex is 'cold'. v=-1*v; end B=zeros(n,2*n-1); %We initialize B where we will store the fiedler vector into its triangular-graph form. index=0; %The index will keep track of which vertex of the fiedler vector we are currently placing for k=0:n-1, i=n-k; for j = n-k:n+k; index=index+1; B(i,j)=v(index); %We place the value of the fiedler vector in the appropriate location in B end end B B=flipud(B); %Must flip before meshing to make the figure look the same as the matrix... odd that mesh doesn't do this automatically! mesh(B)