Is there an implementation of the resistance distance matrix (or just resistance matrix) for graphs available in Mathematica?


2 Answers 2


Based on the definition from the Wikipedia article, this should give you the resistance distance matrix of the graph g:

With[{Γ = PseudoInverse[KirchhoffMatrix[g]]},
 Outer[Plus, Diagonal[Γ], Diagonal[Γ]] - Γ - Transpose[Γ]

This is based on 2012rcampion's answer.

GraphResistanceMatrix[g_?GraphQ] := 
 Module[{kirchhoffMatrix, pseudoInverse, diagonal}, 
  kirchhoffMatrix = KirchhoffMatrix[g]; 
  pseudoInverse = PseudoInverse[kirchhoffMatrix];
  diagonal = Diagonal[pseudoInverse];
   Outer[Plus, diagonal, diagonal] - pseudoInverse - 

To test this I did

data = EntityValue[
   EntityFunction[graph, graph["VertexCount"] === 21]], 
  "ResistanceMatrix", "NonMissingEntityAssociation"]

enter image description here

Then I did

CheckResistanceMatrix = GraphResistanceMatrix[Graph[#1]] === #2 &;

Then I did


and all the values from GraphResistanceMatrix matched GraphData's precomputed "ResistanceMatrix" value.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.