Ask Your Question
0

defining function for graph (help needed)

asked 2013-02-27 07:14:51 -0500

jtaa gravatar image

updated 2014-12-10 09:02:56 -0500

I need help defining a function that does the following (I'm very new to Python/Sage).

I need a function called ihara(G) where G is any graph input by the user.

I need the function ihara(G) to return the Z resulting from all the calculations below:

D = G.to_directed()
L = D.line_graph()
L.delete_edges([((x,y,None), (y,x,None)) for x,y in G.edges( labels=None)])
L.delete_edges([((x,y,None), (y,x,None)) for y,x in G.edges( labels=None)])

IM = identity_matrix(QQ,D.size())
T = L.adjacency.matrix()

var('u')
X = IM-u*T
Z = X.det()

Could anybody help me with this? or at least get me started in the right direction...

edit retag flag offensive close merge delete

Comments

Is what you want the same as

sage: g=graphs.CycleGraph(5)
sage: g.ihara_zeta_function_inverse()

?

FrédéricC gravatar imageFrédéricC ( 2014-12-10 13:19:04 -0500 )edit

1 answer

Sort by » oldest newest most voted
2

answered 2013-02-27 08:41:17 -0500

fidbc gravatar image

To declare a function you can just follow this scheme

def function_name(<arguments>):
   "Optional documentation string."
   <Python/Sage instructions, could be multiple lines of code>
   return <variable/expression>

In your case, I guess you'd like to receive G as an argument, so it could be of the form

def ihara( G ):
   <your source code here>
   return Z

For more details on functions you can consult this webpage.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2013-02-27 07:14:51 -0500

Seen: 105 times

Last updated: Dec 10 '14