Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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 – Dr. belisarius 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.