# Sage: christoffel symbol calculation issue, help...

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

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 close merge delete

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.

( 2016-03-04 04:58:09 +0200 )edit

Sort by ยป oldest newest most voted

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

more