Home > matgraph > @graph > resistance.m

resistance

PURPOSE ^

R = resistance(g) --- calculate resistances between vertices

SYNOPSIS ^

function R = resistance(g)

DESCRIPTION ^

 R = resistance(g) --- calculate resistances between vertices
 g is a connected, undirected weighted graph. Returns a matrix R whose 
 (i,j)-entry is the effective resistance between vertices i and j 
 where we assume each edge represents a resistance equal to the weight 
 of the edge.

 Author: Somit Gupta

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function R = resistance(g)
0002 % R = resistance(g) --- calculate resistances between vertices
0003 % g is a connected, undirected weighted graph. Returns a matrix R whose
0004 % (i,j)-entry is the effective resistance between vertices i and j
0005 % where we assume each edge represents a resistance equal to the weight
0006 % of the edge.
0007 %
0008 % Author: Somit Gupta
0009 
0010 if(isconnected(g)) %to test for connected graphs as the formulae works only for connected graphs
0011     l= laplacian(g); % gets the laplacian of the graph
0012     m=nv(g); %no of vertices
0013     % R=[0];
0014     lp=pinv(l);
0015 
0016     d=diag(lp);
0017     rowMatrix=d*ones(1,m);
0018     R = rowMatrix+rowMatrix'-2*lp;
0019 else
0020     error('The graph is not connected')
0021 end

Generated on Thu 13-Mar-2008 14:23:52 by m2html © 2003