Skip to main content

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
85 votes
2 answers
5k views

Internal`Bag inside Compile

Since Internal`Bag, Internal`StuffBag and Internal`BagPart can be compiled down, it is a ...
halirutan's user avatar
  • 113k
53 votes
6 answers
44k views

How to calculate scalar curvature, Ricci tensor and Christoffel symbols in Mathematica?

I am seeking a convenient and effective way to calculate such geometric quantities. I've used packages like TensoriaCalc, but they don't work at all time. Sometimes,...
Zoe Rowa's user avatar
  • 665
7 votes
2 answers
6k views

Contracting with Levi-Civita (totally antisymmetric) tensor

I have an array $v_{ijk}$ which is effectively a rank-$3$ tensor with dimensions $3\times3\times3$, and I need to contract it with $e^{ijk}$, i.e. evaluate $v_{ijk} e^{ijk}$ (see Einstein convention)....
S D N's user avatar
  • 71
18 votes
5 answers
5k views

Ways to compute inner products of tensors

One way to evaluate the following sums is combining Table and Sum: $u_{abcd} = \sum_{e=1}^3 v_{aeb}w_{ced}$ $q_{ab} = \sum_{d,e=1}^3 v_{d e a}w_{deb}$ It will look like ...
sjdh's user avatar
  • 7,757
11 votes
5 answers
3k views

Elementwise join

I have two tensors of arbitrary but equal rank n (and equal dimensions): A and B, and I want to get a third tensor of rank n + 1,...
Andrew Spott's user avatar
  • 1,581
9 votes
1 answer
1k views

How to define an orthogonal basis in the right way?

I am trying to work with the vector notation without defining vector components explicitly. $Assumptions = (x | y | z) \[Element] Vectors[3] The vectors ...
galadog's user avatar
  • 247
3 votes
2 answers
4k views

Using the epsilon tensor in Mathematica

I'm having a great deal of trouble getting started on a weekly homework assignment in Mathematica. The assignment requires we use the epsilon tensor which is apparently built into Mathematica as ...
Merry's user avatar
  • 85
26 votes
4 answers
2k views

What is the definition of Curl in Mathematica?

I have a usual mathematical background in vector and tensor calculus. I was trying to use the differential operators of Mathematica, namely Grad, ...
Hosein Rahnama's user avatar
22 votes
2 answers
13k views

Using Mathematica for tensor analysis

Has anybody used tensors in Mathematica? How to properly work with them? I find Mathematica not very friendly in this field, as I am defining my own functions for lowering & raising indices, ...
Vladimir's user avatar
  • 1,503
7 votes
3 answers
2k views

How to implement Einstein summation convention with differential operators

Statement of this problem: In the textbook, the following differential equilibrium equations can be expressed by tensors: Using Einstein's summation convention, the formula in the figure above can be ...
A little mouse on the pampas's user avatar
11 votes
2 answers
982 views

How to read off coefficients of tensor-like expression in a speedy way?

I am considering identities involving t[a, b, c, d, ...], where number of indices is fixed. t has the cyclic property so that <...
Joonho Kim's user avatar
8 votes
2 answers
5k views

Compute covariant derivative in Mathematica

I need to compute covariant derivatives in Mathematica. Searching online I just found the package "Ricci" which only does symbolic computations: I instead need to do actual computations. This is ...
user372511's user avatar
16 votes
2 answers
5k views

How to represent and manipulate abstract indexed vector (or tensor) expressions?

I have a couple abstract indexed quantities, both differential elements $dx = dx^\mu e_\mu + x^\mu de_\mu$ $du = du^\mu e_\mu + u^\mu de_\mu$ I can compute the expression $(dx + du) \cdot (dx + du) ...
Peeter Joot's user avatar
  • 6,418
11 votes
2 answers
917 views

Symbolic tensor simplifications and the identity matrix

How can I get Mathematica to simplify the following expressions, with $Assumptions including Element[n,Integers], n > 0, and <...
Kevin S. Van Horn's user avatar
7 votes
1 answer
581 views

Symbolic calculation with generators and relations

Is it possible to do the following in Mathematica: Define an algebra $A$ via generators and relations and multiply some tensors in $A\otimes A$ (and of course simplify the relations via the relations)...
user avatar
7 votes
1 answer
272 views

Derivative of real antisymmetric matrix in mathematica

Is it possible to find the derivative of components of a real antisymmetric matrix using index notation? Eg: I have a very large real antisymmetric matrix. Then from Matrix Cookbook, we know the ...
Jasmine's user avatar
  • 1,225
3 votes
1 answer
500 views

Cartesian tensor gradient

Let $\mathbf{R} = [x,y,z]$ be a cartesian vector, $R_\alpha$ it's tensor representation with $\alpha = x,y,z$ and let $R=\sqrt{x^2 + y^2 + z^2}$ be its norm. I want to do tensor derivatives of the ...
Jonatan Öström's user avatar
26 votes
1 answer
3k views

Nearest Kronecker Product

Some people (see The ubiquitous Kronecker product by Van Loan) have worked on finding two matrices $\mathbf A$,$\mathbf B$ of specified size whose tensor product $\mathbf A\otimes\mathbf B$ is closest ...
pdmclean's user avatar
  • 1,398
16 votes
2 answers
1k views

Python's einsum equivalent in Mathematica?

Python's numpy has einsum function, which allows to express wide range of combinations of ND-arrays multiplications, transposings, convolutions etc in one short ...
Dims's user avatar
  • 735
15 votes
1 answer
3k views

Nesting Parallel processes

I just attempted to run code that had nested ParallelMap[] functions. It generates the error message: ParallelMap::subpar: Parallel computations cannot be nested; ...
Jagra's user avatar
  • 14.4k
13 votes
2 answers
1k views

How to take derivative of parameterized coordinate?

Suppose I have a vector in $\mathbb{R}^n$ but $n$ is not known in advance. I want to be able to write functions which operate on the components of that vector, and then I'd like to be able to take ...
Tom's user avatar
  • 295
11 votes
3 answers
534 views

Looking for an elegant way to construct this tensor-product-ish list

I would like to make the following matrix: ...
Alexander Gruber's user avatar
10 votes
4 answers
2k views

Simplifying the trace of a matrix expression

I have a long expression involving matrices that I derived using the NCAlgebra package. Can I simplify the trace of the expression? For example, say b is a scalar (...
PW Laslo's user avatar
  • 101
10 votes
1 answer
373 views

TensorReduce and Dot

I'm manipulating abstract tensors with Mathematica. I have a question. With the assumptions $Assumptions = (R | r) ∈ Arrays[{4}]; I can do two operations: ...
MaPo's user avatar
  • 909
10 votes
1 answer
410 views

Function to convert TensorContract[_TensorProduct, indices] into equivalent Dot + Tr version

Mathematica can use either Dot + Tr to represent some tensors, or TensorContract + ...
Carl Woll's user avatar
  • 131k
10 votes
2 answers
6k views

Perturbation theory in general relativity using xAct

I'm trying to use the xAct Mathematica package for manipulating tensors, and I'd like to plug in a metric into the perturbation equations to first order in general relativity, and have everything ...
user1997744's user avatar
8 votes
2 answers
557 views

How to force Series[] to compute expansions by considering non commutative multiplication?

I wish to compute the Taylor series expansion of the following iteration method $x_{k+1}=x_k-f'(x_k)^{-1}f(x_k)$ up to four terms of error ($e_k=x_k-\alpha$). When this is a scalar iteration, I very ...
M.J.2's user avatar
  • 491
6 votes
2 answers
1k views

Perform matrix/tensor contractions more efficiently

Problem: explicit index contractions for matrices using the Sum command take too long, and I want to improve the performance for complicated computations. Let me ...
Stan's user avatar
  • 951
2 votes
0 answers
144 views

Implementing the symbolic identity matrix $I$

I am working with symbolic tensors within Mathematica and I wanted to ask if there is a way to have a symbolic identity tensor.
relativeentropy's user avatar
14 votes
0 answers
514 views

Can I use symbolic tensors for simple linear algebra and calculus?

As an example, I'd like to calculate this symbolic derivative: $\frac{\partial}{\partial b}(x-A.b)^{\mathsf{T}}.(x-A.b)$ where $x$ and $b$ are vectors and $A$ is a matrix. What I tried is this: <...
Niki Estner's user avatar
  • 36.1k
8 votes
3 answers
541 views

How is Grad defined for array particularly in non-Cartesian coordinates?

This question can be viewed as a follow-up of What is the definition of Curl in Mathematica? First argument of Grad can be an array, but what definition does ...
xzczd's user avatar
  • 66.2k
7 votes
2 answers
830 views

Solving antisymmetric tensorial equation

Assume we have the following Tensor objects: \begin{equation} F_{i}{}^{j}\;and\;S_{ij}{}^{k}, \end{equation} where the components of $F$ are known, and we would like to solve for the components of $S$ ...
Imagine's user avatar
  • 135
6 votes
2 answers
654 views

Looking for a package for Cartan formalism in Mathematica

I want to convert a gravity action in terms of differential forms to tensorial expressions. A procedure known as tetrad formalism/Cartan formalism like Palatini action in this page: CARTAN FORMALISM ...
physics portal's user avatar
5 votes
1 answer
483 views

Conveniently solving tensor equations in which the contained tensors have various symmetries

How do I conveniently solve tensor equations in which the contained tensors have various symmetries?
Bill N's user avatar
  • 216
5 votes
1 answer
2k views

Linearized Einstein Equations with Mathematica

I need to compute the linearised Einstein Equations around a fixed metric $g_{\mu \nu}$ which is not the flat metric. Someone knows any Mathematica package or a review that can help me?
Andy Bale's user avatar
  • 151
5 votes
1 answer
649 views

Efficient implementation of tensorial Rayleigh product

I am interested in the tensor product $\hat{B} = A \star B$ (which at least I know as Rayleigh product), defined with components \begin{equation} \hat{B}_{i_1 i_2 ... i_ n} = \sum_{j_1 = 1}^d \sum_{...
Mauricio Fernández's user avatar
4 votes
1 answer
396 views

Expanding tensors

This is a follow-up on / clarification of this thread. I have the following in a notebook: ...
arriopolis's user avatar
4 votes
1 answer
1k views

Computing Christoffel symbols of the second kind [duplicate]

I want to compute the Christoffel-symbol for a given metric. I am using the code here, but I am missing something. The Chrisfoffel-symbol formula is $\Gamma^{\mu}_{\phantom{\mu}\nu\sigma}=\frac{1}{2}g^...
JD_PM's user avatar
  • 163
4 votes
1 answer
2k views

Efficient tensor product followed by contraction [duplicate]

Say I want to efficiently evaluate $\sum_{kl}A_{ikjl}B_{kl}$ where $A$, $B$ are numerical tensors. This has been discussed before but with no focus on efficiency. A straightforward way as mentioned ...
jhrmnn's user avatar
  • 265
3 votes
1 answer
2k views

How to create simple (tensor) product spaces?

Is it possible to work with simple tensor product spaces, like multiplying product states from quantum mechanics? I basically have a simple two dimensional vector space, whose elements are ...
Oliver's user avatar
  • 33
3 votes
1 answer
1k views

Covariant derivative given Christoffel symbols

I've been trying to take covariant derivative of various quantities along various surfaces in Mathematica, but I keep running into issues, frequently I get a tensor with the wrong dimension. Using the ...
Noahb32's user avatar
  • 31
3 votes
4 answers
212 views

Fast way to create $[ I_4\otimes e_1,\ \dots ,\ I_4 \otimes e_T]$?

Is there a fast way to construct this matrix? $\left[\begin{array}{c} I_4\otimes e_1\\ \vdots \\ I_4 \otimes e_T \end{array}\right]$ $e_i$ is the $i$-th column of the matrix $I_T$, $\otimes$ is the ...
An old man in the sea.'s user avatar
2 votes
2 answers
151 views

Problem verifying expression with 3D vectors

I am unable to verify that my vector expressions are equivalent. I want it to say true or false. ...
Megamatics's user avatar
2 votes
2 answers
1k views

Change of basis for a rank 3 Cartesian tensor

I have a Cartesian tensor $\chi_{ijk}$ and I want to express the elements in terms of a new basis to get $\chi_{ijk}^\prime$. The transformation is represented using $a_{ij}$. The tensor transforms ...
user27480's user avatar
1 vote
1 answer
192 views

Calculating Einstein tensor components in Kaluza-Klein model

I try to calculate the Einstein tensor of Kaluza-Klein model from this paper. It is given by Equation (55) $ G_{\alpha\beta} = \frac{\nabla_\beta (\partial_\alpha \phi)}{\phi} - \frac{1}{2\phi^2} \...
Dr. phy's user avatar
  • 287
23 votes
3 answers
4k views

Higher order SVD

Does anyone know how to do a higher order SVD in Mathematica ? A good reference seems to be here http://www.sandia.gov/~tgkolda/pubs/pubfiles/SAND2007-6702.pdf but I don't understand their formalism ...
faysou's user avatar
  • 11k
12 votes
1 answer
2k views

Computations in the exterior algebra

I want to be able to compute with explicit exterior algebras of vector spaces. For example, given a real vector space $V$ of $3 \times 3$ matrices, I want to consider expressions of the form $v\wedge ...
Renato G. Bettiol's user avatar
11 votes
1 answer
1k views

A comprehensive list of all correct input formats for [[experimental]] Neural Net functions?

Question: correct formats for Mathematica's NetTrain function Explanation of the problem Background So Mathematica 11 was released earlier this month, and while there are many improvements and they ...
SumNeuron's user avatar
  • 5,422
10 votes
4 answers
504 views

How can I automate this tensor computation?

I am doing this work by hand, but it takes a lot of time and I make several calculation errors, so I was thinking to make Mathematica to calculate this for me, but I am stuck at the very beginning. I ...
mattiav27's user avatar
  • 6,727
10 votes
3 answers
646 views

Reduce the output from tuples by including symmetry?

I need all the possible 3x3 binary tensors, but I'd like to have this account for symmetries. I've started by using the Tuples command. Tuples[{1, 0}, {3, 3}] ...
dpholmes's user avatar
  • 683