Sign up ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have a weighted graph and I want its graph Laplacian matrix (what Mathematica calls the Kirchhoff matrix in the unweighted case). Is there an easy way to get this?

For example, the command:

WeightedAdjacencyMatrix[Graph[{0 \[UndirectedEdge] 1},EdgeWeight -> {3}]]//MatrixForm

returns the matrix

0   3
3   0


KirchhoffMatrix[Graph[{0 \[UndirectedEdge] 1}, EdgeWeight -> {3}]] //MatrixForm


1 -1
-1 1

whereas I would like

3 -3
-3 3

I can do it in an ugly way, but I am wondering if there is a beautiful way to do it.


I wrote a small function to do this, and it works.

     WeightedKirchhoffMatrix[G_] := 
    (M = WeightedAdjacencyMatrix[G];
     n = Length[M];
     e = Table[1, {i, n}];
     DiagonalMatrix[e.M] - M)
share|improve this question
WeightedKirchhoffMatrix[G_] := (DiagonalMatrix[Total[#, {1}]] - #) & [WeightedAdjacencyMatrix[G]] – J. M. Apr 11 '13 at 18:39

1 Answer 1

up vote 1 down vote accepted

Somewhat shorter:

wKM[g_]:= DiagonalMatrix[Tr /@ Transpose@#] - # &@ WeightedAdjacencyMatrix[g]
share|improve this answer
If the matrix is symmetrical, the Transpose part could be ommited – belisarius has settled Apr 11 '13 at 15:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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