Ask Your Question
1

What is the significance of "." other than in a file name?

asked 2018-04-09 04:36:59 +0100

wxman112 gravatar image

I continue to stumble over the "." in structures other than in filenames. For example,

Dr(t) = sol[0].rhs

where D is the first derivative of r and "sol" has been defined as the Sagemath function "solve" in lines before this one.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
4

answered 2018-04-09 09:31:53 +0100

slelievre gravatar image

This is the way to apply a method to an object.

Very often, instead of f(x), the notation in Python, and therefore in SageMath, will be x.f().

Follow a Python tutorial or a Sage tutorial to learn more.

In the example you mention, sol[0] is an equation, and to extract its right-hand side, you apply the method "rhs" to it, by doing sol[0].rhs().

This is very efficient, especially when you need to apply several operations in a row.

For example, starting from a graph, say you want to compute its adjacency matrix, then get the characteristic polynomial of this matrix, then factor this polynomial.

You can do g.adjacency_matrix().charpoly().factor(), which maybe better shows the sequence of operations, and avoids nested parenthesis, if you compare to writing factor(charpoly(adjacency_matrix(g))).

edit flag offensive delete link more

Comments

THANK YOU, THANK YOU!! I'm just starting out using SageMath. Even at this early stage it's been a real time-saver. There are some structures, however, that are confusing and trying to find answers can be difficult. This one is a case in point. I scrolled through the Python codes but I can see I need to invest time in the tutorial(s). Thanks again for pointing towards the resources I'll need.

wxman112 gravatar imagewxman112 ( 2018-04-12 04:48:11 +0100 )edit

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-04-09 04:36:59 +0100

Seen: 273 times

Last updated: Apr 12 '18