sage - 替换 sage 中的变量值

标签 sage

我使用以下代码来计算 Schwartzchild 时空的 Kretschmann 标量:

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

它有效(我得到了正确的符号表达式),但现在我想用一个值替换变量 m。我尝试过:

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

但是这些都不起作用。如何使替换 m=10?

最佳答案

我自己找到了解决方案:在替换之前必须考虑 kr 的表达式:

kr.expr().subs(m=10)

关于sage - 替换 sage 中的变量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59390531/

相关文章:

python - 从符号多项式获取向量空间坐标

python - 在函数中打印变量标签

class - 如何使用额外的方法在 Sage 中创建新的 Graph 类?

python - 打印字符串时出现 SageMathCell ValueError(有时)

cryptography - 单位群子群中离散对数的 SAGE 实现

python - 如何明确地写出符号函数的导数?

python - numpy.float64 类型和 is_integer() 问题

python 圣人 : How do I computer a nullspace (kernel) for a stoichiometric matrix?