Take the 2-minute tour ×
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

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)
share|improve this question
1  
WeightedKirchhoffMatrix[G_] := (DiagonalMatrix[Total[#, {1}]] - #) & [WeightedAdjacencyMatrix[G]] –  J. M. Apr 11 '13 at 18:39
add comment

1 Answer

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 Apr 11 '13 at 15:09
add comment

Your Answer

 
discard

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.