Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Substituting variable value in sage

Tags:

sage

I use the following code to calculate the Kretschmann scalar of the Schwartzchild spacetime:

print("Initialization of  manifold, chart, and metric. Definitions of constants.")
M=Manifold(4,'M',structure='Lorentzian')
X.<t,r,th,ph> = M.chart(r"t r:(0,+oo) th:(0,pi):\theta ph:(0,2*pi):\phi")
m=var('m')

g=M.metric()

g[0,0]=-(1-2*m/r)
g[1,1]=1/(1-2*m/r)
g[2,2]=r^2
g[3,3]=r^2*sin(th)^2


print('Calculating Riemann tensor')
R = g.riemann()
print(R[:])
uR=R.up(g)
dR=R.down(g)

print('Calculating Kretschmann scalar')
kr= uR['^{abcd}']*dR['_{abcd}']
print(kr.expr())

It works (I get the correct symbolic expression), but now I want to substitute a value for the variable m. I have tried with:

kr.substitute(m==10)
kr.subs(m==10)
kr.substitute_expression(m==10)

but none of these work. How can I make the substitution m=10?

like image 577
mattiav27 Avatar asked Feb 15 '26 12:02

mattiav27


1 Answers

I have found the solution myself: one has to consider the expression of kr before substituting:

kr.expr().subs(m=10)
like image 179
mattiav27 Avatar answered Feb 21 '26 03:02

mattiav27



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!