3
$\begingroup$

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

and

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

returns

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.


Edit

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)
$\endgroup$
1
  • 1
    $\begingroup$ WeightedKirchhoffMatrix[G_] := (DiagonalMatrix[Total[#, {1}]] - #) & [WeightedAdjacencyMatrix[G]] $\endgroup$ Commented Apr 11, 2013 at 18:39

1 Answer 1

4
$\begingroup$

Somewhat shorter:

wKM[g_]:= DiagonalMatrix[Tr /@ Transpose@#] - # &@ WeightedAdjacencyMatrix[g]
$\endgroup$
1
  • $\begingroup$ If the matrix is symmetrical, the Transpose part could be ommited $\endgroup$ Commented Apr 11, 2013 at 15:09

Your Answer

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

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