Changeset 5344:4296f1e74ae6


Ignore:
Timestamp:
06/14/07 15:46:57 (6 years ago)
Author:
Robert L Miller <rlm@…>
Branch:
default
Message:

Kirchhoff matrix, Tom Boothby, SAGE Days 4 (during Jim's talk).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sage/graphs/graph.py

    r5341 r5344  
    33433343        return matrix(cols, sparse=sparse).transpose() 
    33443344 
     3345    def kirchhoff_matrix(self): 
     3346        """ 
     3347        Returns the Kirchhoff matrix (a.k.a. the Laplacian) of the graph. 
     3348         
     3349        The Kirchhoff matrix is defined to be D - M, where D is the diagonal 
     3350        degree matrix (each diagonal entry is the degree of the corresponding 
     3351        vertex), and M is the adjacency matrix. 
     3352         
     3353        AUTHOR: 
     3354            Tom Boothby 
     3355         
     3356        EXAMPLES: 
     3357            sage: G = graphs.PetersenGraph() 
     3358            sage: G.kirchhoff_matrix() 
     3359            [ 3 -1  0  0 -1 -1  0  0  0  0] 
     3360            [-1  3 -1  0  0  0 -1  0  0  0] 
     3361            [ 0 -1  3 -1  0  0  0 -1  0  0] 
     3362            [ 0  0 -1  3 -1  0  0  0 -1  0] 
     3363            [-1  0  0 -1  3  0  0  0  0 -1] 
     3364            [-1  0  0  0  0  3  0 -1 -1  0] 
     3365            [ 0 -1  0  0  0  0  3  0 -1 -1] 
     3366            [ 0  0 -1  0  0 -1  0  3  0 -1] 
     3367            [ 0  0  0 -1  0 -1 -1  0  3  0] 
     3368            [ 0  0  0  0 -1  0 -1 -1  0  3] 
     3369 
     3370        """ 
     3371        M = self.am() 
     3372        A = list(-M) 
     3373        S = [sum(M[i]) for i in range(M.nrows())] 
     3374        for i in range(len(A)): 
     3375            A[i][i] = S[i] 
     3376        return M.parent()(A) 
     3377 
    33453378    def __bit_vector(self): 
    33463379        vertices = self.vertices() 
Note: See TracChangeset for help on using the changeset viewer.