Wolfram Language Paclet Repository

Community-contributed installable additions to the Wolfram Language

Primary Navigation

    • Cloud & Deployment
    • Core Language & Structure
    • Data Manipulation & Analysis
    • Engineering Data & Computation
    • External Interfaces & Connections
    • Financial Data & Computation
    • Geographic Data & Computation
    • Geometry
    • Graphs & Networks
    • Higher Mathematical Computation
    • Images
    • Knowledge Representation & Natural Language
    • Machine Learning
    • Notebook Documents & Presentation
    • Scientific and Medical Data & Computation
    • Social, Cultural & Linguistic Data
    • Strings & Text
    • Symbolic & Numeric Computation
    • System Operation & Setup
    • Time-Related Computation
    • User Interface Construction
    • Visualization & Graphics
    • Random Paclet
    • Alphabetical List
  • Using Paclets
    • Get Started
    • Download Definition Notebook
  • Learn More about Wolfram Language

STensor

Guides

  • Get Started

Tech Notes

  • Basic Tensor Computation
  • ComputationWithMetric

Symbols

  • ChristoffelSymbol
  • CreateTensor
  • EinsteinTensor
  • Inverse
  • IsMetric
  • LineElement
  • RicciScalar
  • RicciTensor
  • RiemannTensor
  • SCoordinateTransform
  • STensor
  • STensorQ
  • Symmetrize
  • TensorRank
  • TensorSymmetry
  • Tr
  • VolumeElement
  • WeylTensor
ComputationWithMetric
2
S
Metric
Friedmann–Lemaître–Robertson–Walker metric
Schwarzschild Metric
Vaidya Metric
2
S
Metric
Some computation examples are done based on
2
S
manifold.

Geodesic Equations

Set metric and general vector tensor:
In[4]:=
g=
CreateTensor
"g",{θ,ϕ},DiagonalMatrix[{R^2,R^2Sin[θ]^2}],
IsMetric
True;​​T=
CreateTensor
["T",{1,0},{θ,ϕ},Array[
"T"
##
[θ,ϕ]&,{2}],g]
Out[5]=
STensor
Symbol: T
Rank: {1,0}

Compute geodesic expression:
In[6]:=
geo=T["a"]Grad[T["b"],"a"]
Out[6]=
STensor
Symbol: T ∇(T)
Rank: {1,0}
[b,]
Give geodesic equations:
In[7]:=
Column[Thread[Equal[geo["Components"],0]]]
Out[7]=
T
2
[θ,ϕ]-Cos[θ]Sin[θ]
T
2
[θ,ϕ]+
(0,1)
T
1
[θ,ϕ]+
T
1
[θ,ϕ]
(1,0)
T
1
[θ,ϕ]0
T
2
[θ,ϕ]
(0,1)
T
2
[θ,ϕ]+
T
1
[θ,ϕ]2Cot[θ]
T
2
[θ,ϕ]+
(1,0)
T
2
[θ,ϕ]0

Compute Killing Vector Condition

Set metric and a general vector field:
In[8]:=
g=
CreateTensor
"g",{θ,ϕ},DiagonalMatrix[{R^2,R^2Sin[θ]^2}],
IsMetric
True;​​T=
CreateTensor
["T",{1,0},{θ,ϕ},Array[
"T"
##
[θ,ϕ]&,{2}],g]
Out[9]=
STensor
Symbol: T
Rank: {1,0}

Compute Killing vector field equation:
In[10]:=
ξ=
Symmetrize
[Grad[g["bc"]T["c"],"a"],Symmetric[{"a","b"}]]
Out[10]=
STensor
Symbol: ∇(T g)
Rank: {0,2}
[,ba]
Make every component equal to zero and simplify with coordinate conditions:
In[11]:=
Simplify[​​And@@Thread[Flatten[ξ["Components"]]0],​​R>0&&0≤θ<Pi&&0≤ϕ<2Pi​​]
Out[11]=
Sin[θ]Cos[θ]
T
1
[θ,ϕ]+Sin[θ]
(0,1)
T
2
[θ,ϕ]0&&
(1,0)
T
1
[θ,ϕ]0&&
(0,1)
T
1
[θ,ϕ]+
2
Sin[θ]
(1,0)
T
2
[θ,ϕ]0
Schwarzschild Metric
Create Schwarzschild metric:
In[12]:=
g=
CreateTensor
"g",{t,r,θ,ϕ},​​DiagonalMatrix-1-
2M
r
,
-1
1-
2M
r
,
2
r
,
2
r
2
Sin[θ]
,
IsMetric
True
Out[12]=
STensor
Symbol: g
Rank: {0,2}


Tensors for General Relativity

Compute Riemann tensor:
In[13]:=
Rie=
RiemannTensor
[g]
Out[13]=
STensor
Symbol: Riemann(g)
Rank: {1,3}

In[14]:=
Rie["Components"]//MatrixForm
Out[14]//MatrixForm=
0
0
0
0
0
2M
(2M-r)
2
r
0
0
0
0
M
r
0
0
0
0
M
2
Sin[θ]
r
0
-
2M
(2M-r)
2
r
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
-
M
r
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
-
M
2
Sin[θ]
r
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2M(2M-r)
4
r
0
0
0
0
0
0
0
0
0
0
0
-
2M(2M-r)
4
r
0
0
0
0
0
0
0
0
0
M
r
0
0
0
0
M
2
Sin[θ]
r
0
0
0
0
0
0
-
M
r
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
-
M
2
Sin[θ]
r
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
M(-2M+r)
4
r
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
M
(2M-r)
2
r
0
0
0
0
0
0
-
M(-2M+r)
4
r
0
0
0
0
-
M
(2M-r)
2
r
0
0
0
0
0
0
0
0
0
-
2M
2
Sin[θ]
r
0
0
0
0
0
0
0
0
0
0
0
2M
2
Sin[θ]
r
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
M(-2M+r)
4
r
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
M
(2M-r)
2
r
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
2M
r
0
-
M(-2M+r)
4
r
0
0
0
0
-
M
(2M-r)
2
r
0
0
0
0
-
2M
r
0
0
0
0
0
Compute Ricci tensor, which ends up to be zero tensor:
In[15]:=
Ric=
RicciTensor
[g]
Out[15]=
STensor
Symbol: RicciT(g)
Rank: {0,2}

In[16]:=
Ric["Components"]
Out[16]=
{{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}}
So does the Einstein tensor:
In[17]:=
EinsteinTensor
[g]["Components"]
Out[17]=
{{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}}
Friedmann–Lemaître–Robertson–Walker metric
Set FLRW metric:
In[40]:=
FLRW=
CreateTensor
"g",{t,r,θ,φ},​​DiagonalMatrix-1,
a[t]^2
1-kr^2
,a[t]^2*r^2,a[t]^2*r^2*Sin[θ]^2,​​
IsMetric
True​​
Out[40]=
STensor
Symbol: g
Rank: {0,2}


Conformally Flat

Compute Weyl tensor, which ends up to be zero tensor:
In[59]:=
c=
WeylTensor
[FLRW]
Out[59]=
In[60]:=
Simplify[c["Components"]]//MatrixForm

Volume of the Universe

When k = 1, the r is defined as Sin(ψ) where 0 ≤ ψ ≤ π. Transform coordinate system first:
Then, taking k as 1, the universe is close and computable in terms of its volume. We need to extract induced metric for space part, and simplify with coordinate conditions:
Integrate for the whole coordinate system:
Vaidya Metric
From given Schwarzschild metric:
Do transformation to tortoise coordinate system:
Make constant M into a function of coordinate u, then we obtain the Vaidya Metric:
Compute its Einstein tensor and momentum-energy metric:

© 2025 Wolfram. All rights reserved.

  • Legal & Privacy Policy
  • Contact Us
  • WolframAlpha.com
  • WolframCloud.com