Questions tagged [tensors]

Use this tag for questions that involve tensors. Tensors are fundamental tools for linear computations, generalizing vectors and matrices to higher ranks. Mathematica 9 introduces powerful methods to algebraically manipulate tensors with any rank and symmetry.

Filter by
Sorted by
Tagged with
0 votes
1 answer
62 views

Covariant Derivative

I'm trying to create a function which receives as inputs a coordinate system $x^\mu$, metric tensor $g_{\mu\nu}$, a general tensor $T$ of rank $n$, and a list $I$ of length $n$ that looks like this: $$...
user avatar
  • 123
0 votes
0 answers
49 views

Variation with respect to inverse metric in a Lagrangian density

I am trying to vary the following Lagrangian density with respect to the inverse metric appearing in the equation, but I am having trouble with how to write the right code in Mathematica. I have ...
user avatar
  • 1
3 votes
2 answers
96 views

Set of quadratic forms and linear algebra

I have a set of quadratic forms. $L_{1}=u_1^TJ_{1}u_1$ $L_{2}=u_2^TJ_{2}u_2$ $L_{3}=u_3^TJ_{3}u_3$ where $u_{i=1,2,3}$ - 3$\times$1 vector; where $J_{i=1,2,3}$ - 3$\times$3 matrix; I need to pack ...
user avatar
  • 1,576
4 votes
1 answer
134 views

Tensorial calculus: A question about free and summed indices

I have to start with a full disclosure that I'm new to Mathematica, so this might be easy to resolve in a way that I don't know. I have to implement a triple contraction of an order three tensor $$d^{...
user avatar
  • 199
4 votes
2 answers
109 views

Create a tensor with a well defined symmetry

I want to create a symmetric rank four tensor with this kind of symmetry: {1,2} and {3,4}. How can I implement this using "Array"? ...
user avatar
1 vote
1 answer
80 views

How to compute the divergence of a four-vector?

I have a quadri-vector which is given by u = {(E^(-φ0[r]))*(1 - ε δφ[t, r]), (E^(-φ0[r])) D[ε ξ[t, r], t], 0, 0} and a quantity n which is given by <...
user avatar
0 votes
1 answer
73 views

Mathematica: Partial derivative with respect to tensors

Anyone know how to do the partial derivative of a tensor in d dimensions on Mathematica ? I want to implement something which will calculate directly like that :
user avatar
0 votes
0 answers
50 views

How to compute the covariant derivative of a vector? [duplicate]

I want to compute a derivative of a vector, but I'm new to mathematica (I programmed in other languages). I was advised to work with the diffgeo.m package. What I want to do is calculate using ...
user avatar
0 votes
4 answers
67 views

How to sum over a two tensor with a simple constraint of the form $i<j$?

I am trying to write a sum of the form $$\sum_{i<j}f_{ij}$$ where $i,j\in \{1,2,3,4\}.$ I want to write something like Sum[f[[i,j]], {j,1,4},{i,1,j}] but then ...
user avatar
  • 81
2 votes
0 answers
56 views

Manipulating tensorial terms with xAct, ToCanonical is not perfoming well

I am trying to calculate perturbations of some complicated Lagrangians. Using xAct and more specifically VarD to perform the perturbations the expressions become ...
user avatar
  • 21
3 votes
1 answer
93 views

Creating a rank 4 tensor

I am struggling with creating the rank-4 matrix T in Mathematica. The matric is defined as $T_{i,j,k,l}= n_i n_j n_k n_l-(\delta_{i,j} n_k n_l +\delta_{i,k} n_j n_l+\delta_{i,l} n_k n_j+\delta_{j,l} ...
user avatar
  • 131
1 vote
2 answers
270 views

How do I get the Schwarzschild solution from the Einstein Equations?

Consider the Schwartzchild-like metric $$ds^2=-A(r)dt^2+B(r)dr^2+r^2(d\theta^2+\sin^2\theta d\phi^2).$$ The Einstein field equations for this metric reduce to $$R_{\mu\nu}=0,$$ which is also known as ...
user avatar
  • 119
0 votes
1 answer
306 views

How to do Einstein Summation in Mathematica?

I am working with the de Sitter metric which takes the form $$g=\tau^{-2}\left(-\left(\Lambda / 3-\tau^{2}\right)^{-1} d \tau^{2}+\left(\Lambda / 3-\tau^{2}\right) d t^{2}+g_{\mathbb{S}^{2}}\right)$$ ...
user avatar
  • 81
1 vote
1 answer
79 views

Simple and efficient construction of tensor product operators

Problem Description I'm using mathematica to study a problem in quantum mechanics, which is naturally understood in terms of vector spaces. In the simplest example, suppose we have a 16-dimensional ...
user avatar
  • 595
3 votes
1 answer
56 views

How to perform delta and sum functions in KroneckerProduct in Mathemtica?

I am trying to simulate a tensors which includes sum and kroneckerdelta functions, Sum[KroneckerDelta[b, d] gamma1[a, j] gamma2[j, c], {j, 1, n}]. So I have used <...
user avatar
  • 139
1 vote
0 answers
76 views

Code for calculating the Kretschmann scalar + Ricci tensor, Christoffel symbols etc. in Mathematica

From How to calculate scalar curvature, Ricci tensor and Christoffel symbols in Mathematica? one has the code for calculating the Reimann tensor which is as follows ...
user avatar
1 vote
1 answer
52 views

General::ivar: 3 is not a valid variable. error when calculating Ricci tensor

I'm having troubles when evaluating the Ricci tensor in Mathematica. ...
user avatar
4 votes
2 answers
243 views

How to apply a linear transformation to a tensor?

I would like to apply a linear transformation to a tensor. My linear transformation is encoded by a matrix, for example M = Table[m[i, j], {i, 4}, {j, 4}] Take some ...
user avatar
  • 143
5 votes
1 answer
184 views

Third/Fourth derivative of cross-entropy loss

I need a nice formula for the third (or fourth derivative if it's easier) of cross-entropy loss $\frac{\partial^3 J}{\partial z^3}$ where $$J(p(z)) = -\sum_i q_i\log p(z)_i$$ $$p(z)_i=\frac{\exp z_i}{\...
user avatar
2 votes
0 answers
87 views

Implementing einsum in Mathematica

I've been using Carl Woll's einsum function, but it's missing the ability to handle repeated indices. For instance np.einsum('i,i->i',w, w) will perform a ...
user avatar
0 votes
0 answers
97 views

Christoffel symbol of the first kind [duplicate]

Suppose that we are given a metric $$ds^2=-\left(1-\frac{r_s}{r}\right)c^2dt^2+\left(1-\frac{r_s}{r}\right)^{-1}dr^2+r^2d \theta^2+r^2\sin^2(\theta)d \phi^2.$$ Given the Catalogs of Spacetimes pdf we ...
user avatar
  • 119
2 votes
2 answers
78 views

Construct tensor with complicated symmetries

I have a tensor with following symmetries ...
user avatar
  • 15.7k
0 votes
0 answers
52 views

Finding transformation matrix for a coordinate transform

I have a matrix in two different bases. Suppose they are called $g_{\mu \nu}$ in one basis and $\eta_{ab}$ in the other basis. If the transformation between the bases is represented by $T_{\mu}^{\text{...
user avatar
1 vote
0 answers
70 views

xAct tensor product

I am a beginner of xAct for computation in GR. I am doing component computation in specified charts, and quite often I need to extract the list of components by the function ...
user avatar
2 votes
1 answer
58 views

Expand tensor expressions with matrix powers and outer products

I would like to have TensorExpand distribute across repeated matrices involving outer products. This question notes that ...
user avatar
0 votes
0 answers
49 views

amount of Riemann scalar on a spherical shell in xAct

how can I Calculate the amount of Riemann scalar on a spherical shell? (i used xCoba and I defined a manifold, then I defined a metric and a chart with theta and phi coordinates but I don't know how ...
user avatar
0 votes
0 answers
52 views

velocity four-vector definition by xAct

I want to define the velocity vector by the following relation and evaluate the norm of the vector by using the Minkowski metric. I have defined the tensor x (position tensor) in xAct, but I don't ...
user avatar
2 votes
1 answer
83 views

Calculating the Laplacian operator using xCoba

I would like to attempt to calculate the laplacian operator using index notation and shoow that it gives the usually expected laplacian in spherical coordinates. I am able to do most of the steps ...
user avatar
  • 635
1 vote
0 answers
47 views

TensorExpand ignores assumptions?

Here's a minimal example to demonstrate my problem: ...
user avatar
2 votes
1 answer
91 views

Matlab code to Mathemtica, Tensor

I am trying to convert a Matlab code to Mathematica. I have a tensor, RF (a,b,c,d) which is constructed from Hamiltonian (Hs) and 2x2 identity matrix (DS): ...
user avatar
  • 139
1 vote
0 answers
29 views

Combining TensorProduct with NonCommutativeMultiply

I'd like to compute tensor products of lists that contain Grassmann variables, i.e. I'd like TensorProduct[] to use NonCommutativeMultiply when multiplying elements rather than the standard ...
user avatar
3 votes
1 answer
74 views

Performing matrix tensor product and getting a sum of its negative entries

I am given a $3 \times 3$ matrix $M$, which only has real entries. Is there an efficient way to do the following two operations with $M$? For a given input $n$, compute the $n$-fold tensor product $M^...
user avatar
2 votes
2 answers
84 views

Overwrite a tensor product notation a_\[TensorProduct]b_ := KroneckerProduct[a, b]

I noticed that the definition of KroneckerProduct and For example TensorProduct[({ {0, 1}, {1, 0} }), ({ {0, 1}, {1, 0} })] Output: {{{{0,0},{0,0}}...
user avatar
  • 823
0 votes
1 answer
54 views

Define Matrix Function in a For loop

Let $g\in\mathcal R^{3\times 3}$ be a given known rank 2 tensor function, $gInv$ its inverse, and $dg\in\mathcal R^{3\times 3\times 3}$ its gradiant: ...
user avatar
  • 1
0 votes
0 answers
58 views

Upper triangular part of tensor

I have created a random real antisymmetric matrix as ...
user avatar
  • 1,163
-1 votes
1 answer
71 views

Generalizing the code for tensor

$ f $ is a real antisymmetric matrix (here for simplicity I have considered $ d = 2 $), where $ 2*d $ is the dimension of the matrix. $$f=\begin{bmatrix}0 & f_{12} & f_{13} & f_{14}\\ -f_{...
user avatar
  • 1,163
1 vote
0 answers
59 views

Perturbation of Einstein tensor around a fixed background in Xact [duplicate]

I want to compute Ricci tensor expansion around a fixed curved background. It is easy to find the formal expansion around the background metric, but I have a reference metric with known components and ...
user avatar
  • 149
2 votes
1 answer
68 views

Equivalence between tensor and matrix

I need have to create a real antisymmetric tensor whose elements are given as $p_{abcd}$ $${\displaystyle p_{abcd}={\begin{cases} +p_{\sigma\left(abcd\right)} & {\text{if }}\sigma(a,b,c,d){\text{ ...
user avatar
  • 1,163
5 votes
3 answers
101 views

Find transformations for two non-square matrices $A$ and $B$

Given two matrices $A$ and $B$: What transformation needs to be applied to transform matrix $A$ into matrix $B$? ...
user avatar
  • 1,576
0 votes
1 answer
122 views

Derivative matrix by vector in Mathematica

This is an excerpt from the article https://www.sciencedirect.com/science/article/abs/pii/S0094114X10000418. How do I write this using vector-matrix operations (...
user avatar
  • 1,576
1 vote
0 answers
57 views

Use xTensor to do the Ricci decomposition

I am new to xTensor. I would like to perform the Ricci decomposition with xTensor, but I do not have any clue. I want to replace the full expression $R_{i,j,k,l}=S_{i,j,k,l}+E_{i,j,k,l}+W_{i,j,k,l}$ ...
user avatar
1 vote
0 answers
165 views

four-dimensional Levi-Civita

Consider we have these four vectors $p^{\mu}$, $q^{\nu}$, $k^{\rho}$, and $k'^{\sigma}$. How can we calculate $$ \epsilon_{\mu\nu\rho\sigma} p^{\mu} q^{\nu} k^{\rho} k′^{\sigma}$$ in Mathematica, ...
user avatar
  • 11
8 votes
2 answers
249 views

What is the best source to learn how to use tensor operations (exterior algebra) in Mathematica?

I'm specifically interested in the TensorProduct,TensorWedge, HodgeDual and certain build in functions to do tensor arithmetic like TensorReduce, TensorExpand. I would like to do exterior algebra ...
user avatar
0 votes
0 answers
27 views

Wrong contraction in Feyncalc when restrictions are imposed over the metric

I have the following tensor which I will manipulate in Feyncalc ...
user avatar
1 vote
1 answer
109 views

How to write this tensor?

How can I write this tensor in Mathematica? $$\mathcal{P}_{ijkl}(N) = \Big( \delta_{ik} - N_iN_k \Big) \Big( \delta_{jl} - N_jN_l \Big) - \dfrac{1}{2} \Big( \delta_{ij} - N_iN_j \Big)\Big( \delta_{kl} ...
user avatar
  • 6,104
2 votes
1 answer
183 views

Create a matrix without definition of dimensions

is it possible to define a matrix without giving its dimensions in Mathematica, e.g. First line: mattest[[1,2]] = 1; Second line: ...
user avatar
  • 1,614
1 vote
1 answer
200 views

how to define unit vectors in mathematica

I'm struggling a little bit trying to understand how to address this problem, I would like to do this in mathematica: is just that I don't know how to do the dot product between $\mathbf{J}$ and $\...
user avatar
1 vote
1 answer
52 views

Differential not returning the answer

I have the following set of rules for differentiation. ...
user avatar
  • 1,163
4 votes
1 answer
87 views

Simplifying the Summation

I have to sum: $$\frac{1}{2} x_{i,k} x_{j,\nu } g_{i,j,k,\mu }+\frac{1}{2} x_{i,k} x_{j,\mu } g_{i,j,k,\nu }+x_{i,l} x_{j,\nu } g_{i,j,l,\mu }+x_{i,\mu } x_{k,l} g_{i,k,l,\nu }$$ g and x are real ...
user avatar
  • 1,163
2 votes
1 answer
135 views

Operator products summing

Is there a way to perform the below summation in Mathematica? $$\frac{\left(\hat{X}_{ij}+\mathbb i\delta_{ij}\right)}{\mathbb{i}}\frac{\left(\hat{X}_{kl}+\mathbb i\delta_{kl}\right)}{\mathbb{i}}$$ I ...
user avatar
  • 1,163

1
2 3 4 5
9