First time here? Check out the FAQ!

Ask Your Question
0

Sage: christoffel symbol calculation issue, help...

asked 9 years ago

this post is marked as community wiki

This post is a wiki. Anyone with karma >750 is welcome to improve it.

I got this trying to compute the example christoffel symbols sage:

sage: var('r t theta phi')
(r, t, theta, phi)
sage: (r, t, theta, phi)
(r, t, theta, phi)
sage: sage: m = matrix(SR, [[(1-1/r),0,0,0],[0,-(1-1/r)^(-1),0,0],[0,0,-r^2,0],[0,0,0,-r^2*(sin(theta))^2]])
sage: sage: print m
[ -1/r + 1 0 0 0]
[ 0 1/(1/r - 1) 0 0]
[ 0 0 -r^2 0]
[ 0 0 0 -r^2*sin(theta)^2]
sage: [ -1/r + 1 0 0 0]

Moreover, I get...

sage: var('r t theta phi')
(r, t, theta, phi)
sage: m = matrix(SR, [[(1-1/r),0,0,0],[0,-(1-1/r)^(-1),0,0],[0,0,-r^2,0],[0,0,0,-r^2*(sin(theta))^2]])    
sage: def christoffel(i,j,k,vars,g):
....:        s = 0
....:        ginv = g^(-1)
....:        for l in range(g.nrows()):
....:               s = s + (1/2)*ginv[k,l]*(g[j,l].diff(vars[i])+g[i,l].diff(vars[j])-g[i,j].diff(vars[l]))
....:            return s
....:     
  File "<ipython-input-3-70e0eaa76f50>", line 6
    return s
            ^
IndentationError: unindent does not match any outer indentation level

What am I doing BAD?

Preview: (hide)

Comments

1

In Python, which is the underlying base language of sage code block is determined by indentation. In your case the return statement should be at the same level (same column) as the for statement.

DBS gravatar imageDBS ( 9 years ago )

1 Answer

Sort by » oldest newest most voted
1

answered 9 years ago

tmonteil gravatar image

updated 9 years ago

The error says it all (IndentationError) : in Python, the indentation is very important. In your case, the return s should start at the same text column than for l in range(g.nrows()):

In general, it is advised to indent with 4 spaces, so, your code should look like:

sage: def christoffel(i,j,k,vars,g):
....:     s = 0
....:     ginv = g^(-1)
....:     for l in range(g.nrows()):
....:         s = s + (1/2)*ginv[k,l]*(g[j,l].diff(vars[i])+g[i,l].diff(vars[j])-g[i,j].diff(vars[l]))
....:     return s
Preview: (hide)
link

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: 9 years ago

Seen: 1,017 times

Last updated: Mar 03 '16