N=20;%The number of pixels along a dimension of the imageA=zeros(N,N);%The imageAdj=zeros(N*N,N*N);%The adjacency matrix%Use 8 neighbors, and fill in the adjacency matrixdx=[-1,0,1,-1,1,-1,0,1];dy=[-1,-1,-1,0,0,1,1,1];forx=1:Nfory=1:Nindex=(x-1)*N+y;forne=1:length(dx)newx=x+dx(ne);newy=y+dy(ne);ifnewx>0&&newx<=N&&newy>0&&newy<=Nindex2=(newx-1)*N+newy;Adj(index,index2)=1;endendendend%%%BELOW IS THE KEY CODE THAT COMPUTES THE SOLUTION TO THE DIFFERENTIAL%%%EQUATIONDeg=diag(sum(Adj,2));%Compute the degree matrixL=Deg-Adj;%Compute the laplacian matrix in terms of the degree and adjacency matrices[V,D]=eig(L);%Compute the eigenvalues/vectors of the laplacian matrixD=diag(D);%Initial condition (place a few large positive values around and%make everything else zero)C0=zeros(N,N);C0(2:5,2:5)=5;C0(10:15,10:15)=10;C0(2:5,8:13)=7;C0=C0(:);C0V=V'*C0;%Transform the initial condition into the coordinate system %of the eigenvectorsfort=0:0.05:5%Loop through times and decay each initial componentPhi=C0V.*exp(-D*t);%Exponential decay for each componentPhi=V*Phi;%Transform from eigenvector coordinate system to original coordinate systemPhi=reshape(Phi,N,N);%Display the results and write to GIF fileimagesc(Phi);caxis([0,10]);title(sprintf('Diffusion t = %3f',t));frame=getframe(1);im=frame2im(frame);[imind,cm]=rgb2ind(im,256);ift==0imwrite(imind,cm,'out.gif','gif','Loopcount',inf,'DelayTime',0.1);elseimwrite(imind,cm,'out.gif','gif','WriteMode','append','DelayTime',0.1);endend
T. Sunada. Chapter 1. Analysis on combinatorial graphs. Discrete geometric analysis. P. Exner, J. P. Keating, P. Kuchment, T. Sunada, A. Teplyaev (编). 'Proceedings of Symposia in Pure Mathematics 77. 2008: 51–86. ISBN 978-0-8218-4471-7.
B. Bollobás, Modern Graph Theory, Springer-Verlag (1998, corrected ed. 2013), ISBN0-387-98488-7, Chapters II.3 (Vector Spaces and Matrices Associated with Graphs), VIII.2 (The Adjacency Matrix and the Laplacian), IX.2 (Electrical Networks and Random Walks).
Wikiwand in your browser!
Seamless Wikipedia browsing. On steroids.
Every time you click a link to Wikipedia, Wiktionary or Wikiquote in your browser's search results, it will show the modern Wikiwand interface.
Wikiwand extension is a five stars, simple, with minimum permission required to keep your browsing private, safe and transparent.