Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Not entirely sure what you are asking. Specially:

  • "at a single step", you want to do this with a single command?
  • "eigenvalue and eigenvectors", later you say you only need the eigenvector.

Would you please clarify what you mean?

Here is something that might help.

Given a matrix M you may obtain eigenvalues and eigenvectors through M.eigenvectors_right(), see documentation for output specification.

Here is a modified version of your code which prints the relevant eigenvectors.

for G in graphs.trees(18):
    if G.diameter()==5:
        L = G.laplacian_matrix()
        spec=L.eigenvalues()
        spec.sort()
        if spec[1]*spec[-1]==1:
            evs = sorted(L.eigenvectors_right())
            if evs[0][2]>1:
                print evs[0][1][0]
            else:
                print evs[1][1][0]

Which should output:

(1, -1, -2.290994448735806?, -2.624327782069139?, -2.624327782069139?, -2.624327782069139?, -1.145497224367903?, -1.145497224367903?, -1.145497224367903?, -1.145497224367903?, 2.290994448735806?, 2.624327782069139?, 2.624327782069139?, 2.624327782069139?, 1.145497224367903?, 1.145497224367903?, 1.145497224367903?, 1.145497224367903?)
(1, -1, -1.463525491562421?, -1.713525491562421?, -1.463525491562421?, -1.713525491562421?, -1.463525491562421?, -1.713525491562421?, -1.463525491562421?, -1.713525491562421?, 1.463525491562421?, 1.713525491562421?, 1.463525491562421?, 1.713525491562421?, 1.463525491562421?, 1.713525491562421?, 1.463525491562421?, 1.713525491562421?)
(1, -2.952846325924191?, -4.139445001431823?, -4.775046463544424?, -4.139445001431823?, -4.775046463544424?, -4.139445001431823?, -4.775046463544424?, 3.957245732488123?, 4.564870950998888?, 4.564870950998888?, 4.564870950998888?, 4.564870950998888?, 1.401849112529162?, 1.617099549550692?, 1.153547507429801?, 1.153547507429801?, 1.153547507429801?)

Not entirely sure what you are asking. Specially:

  • "at a single step", you want to do this with a single command?
  • "eigenvalue and eigenvectors", later you say you only need the eigenvector.

Would you please clarify what you mean?

Here is something that might help.

Given a matrix M you may obtain eigenvalues and eigenvectors through M.eigenvectors_right(), see documentation for output specification.

Here is a modified version of your code which prints the relevant eigenvectors.

for G in graphs.trees(18):
    if G.diameter()==5:
        L = G.laplacian_matrix()
        spec=L.eigenvalues()
        spec.sort()
        if spec[1]*spec[-1]==1:
            evs = sorted(L.eigenvectors_right())
            if evs[0][2]>1:
                print evs[0][1][0]
            else:
                print evs[1][1][0]

Which should output:

(1, -1, -2.290994448735806?, -2.624327782069139?, -2.624327782069139?, -2.624327782069139?, -1.145497224367903?, -1.145497224367903?, -1.145497224367903?, -1.145497224367903?, 2.290994448735806?, 2.624327782069139?, 2.624327782069139?, 2.624327782069139?, 1.145497224367903?, 1.145497224367903?, 1.145497224367903?, 1.145497224367903?)
(1, -1, -1.463525491562421?, -1.713525491562421?, -1.463525491562421?, -1.713525491562421?, -1.463525491562421?, -1.713525491562421?, -1.463525491562421?, -1.713525491562421?, 1.463525491562421?, 1.713525491562421?, 1.463525491562421?, 1.713525491562421?, 1.463525491562421?, 1.713525491562421?, 1.463525491562421?, 1.713525491562421?)
(1, -2.952846325924191?, -4.139445001431823?, -4.775046463544424?, -4.139445001431823?, -4.775046463544424?, -4.139445001431823?, -4.775046463544424?, 3.957245732488123?, 4.564870950998888?, 4.564870950998888?, 4.564870950998888?, 4.564870950998888?, 1.401849112529162?, 1.617099549550692?, 1.153547507429801?, 1.153547507429801?, 1.153547507429801?)