Ask Your Question
0

Sage: christoffel symbol calculation issue, help...

asked 2016-03-03 22:19:04 +0100

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?

edit retag flag offensive close merge delete

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 ( 2016-03-04 04:58:09 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2016-03-03 22:29:13 +0100

tmonteil gravatar image

updated 2016-03-03 22:30:14 +0100

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
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

1 follower

Stats

Asked: 2016-03-03 22:19:04 +0100

Seen: 928 times

Last updated: Mar 03 '16