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
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
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
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
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
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
17 votes
1 answer
2k views

How can I define or use a new coordinate system?

I want to use the dipole coordinate system as defined in this paper: http://arxiv.org/abs/physics/0606044 I see that Mathematica can do all kinds of vector analysis using different kinds of ...
jvriesem's user avatar
  • 417
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
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
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
14 votes
2 answers
803 views

Efficient way to flatten or transpose-arrayreshape tensors

I have a tensor of dimensions $(2, 100, 100, 2, 100, 100)$ and I want to reshape it to a form of $(2*100*100,2*100*100)$, e.g. Flatten[A,{{1,5,6},{4,2,3}}]. If I ...
Alexis Michailidis'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
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
12 votes
4 answers
857 views

How to rewrite a tensor as a matrix

I put {TensorProduct[{1, 0}, {0, 1}, {0, 1}, {0, 1}, {0, 1}]}/Sqrt[2]//MatrixForm and I got $$ \left( \begin{array}{cc} \left( \begin{array}{cc} \left( \begin{...
Moeki's user avatar
  • 121
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
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
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
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
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
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
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
2 answers
646 views

Make symbols atomic, without losing their type

So, I'd like to define a matrix M, that does not decompose into it's constituents when I do things like Tr[M], but I also want it's type to be retained. (By type, ...
Mahathi Vempati'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
189 views

Fast Sparse Tensor Addition

How can one do a fast sparse tensor addition? Below, I have the following code: We first generate 3 random sparse 1000x1000x1000 tensors with 10^6 entries each. Then, I want to add them. But the usual ...
Florentin Münch's user avatar
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
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
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
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
9 votes
5 answers
5k views

Compute a double dot product between two tensors of rank 3 and 2

I would need help to calculate a double dot product between a rank 3 tensor A and a rank 2 tensor B (A:B) using mathematica. Does someone know how to do that? Thank you for your help!
JYves's user avatar
  • 91
9 votes
1 answer
2k views

Symbolic linear algebra

I would like to know how I can ask Mathematica to expand (and simplify) such an expression : $$ (\alpha A + \beta B)^\top (\alpha A + \beta B) $$ where $\alpha,\beta$ are two real numbers and $A,B$ ...
pitchounet's user avatar
9 votes
3 answers
286 views

Doing ArrayReshape in Mathematica doesn't give desired results

I have an array like this for example, a = ArrayReshape[Range[16], {4, 4}] \begin{align} \left( \begin{array}{cccc} 1 & 2 & 3 & 4 \\ 5 & 6 & ...
Galilean's user avatar
  • 569
9 votes
2 answers
379 views

What's the fastest way to take Mean of a Tensor in given slot?

One should expect that the implementation of the built-in function Mean was quick. However, as I recently observed, this is not true at all, in particular for ...
Henrik Schumacher's user avatar
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
9 votes
1 answer
595 views

inverse of abstract matrix

If you assume the matrix $A$ is invertible, then $A^{-1} \cdot A = I$. Is there an assumption for invertibility in Mathematica 9? How can one make the following evaluate to the identity matrix $I_3$? ...
sjdh's user avatar
  • 7,757
9 votes
1 answer
299 views

Nice use case for symbolic tensors?

I come from before the times of symbolic tensors in Mathematica, and am used to working with concrete tensors and custom commands to contract them using Transpose, Dot, etc. I recently realized that ...
Stijn's user avatar
  • 330
9 votes
1 answer
537 views

Verifying and deriving basic (block) matrix identities

How can I use the new symbolic matrix/tensor capabilities to verify matrix identities, such as (1) or (2) Even better, how can I ask Mathematica to derive expressions for X, Y, Z, and U like ...
Eric's user avatar
  • 333
9 votes
0 answers
184 views

Performance improvements by using Activate and Inactivate

In a question about improving performance of a TensorContract of a TensorProduct, user jose suggested replacing ...
AndreasP's user avatar
  • 598
8 votes
4 answers
615 views

How can I "multiply" nested lists?

Given two nested lists alist={{a,b,c},{d,e,f}} blist={{r,s,t},{x,y,z}} How can I get ...
1729taxi's user avatar
  • 767
8 votes
3 answers
466 views

Equivalent of numpy's newaxis

Numpy has a newaxis object that allows you to insert a new dimension of length 1 into an array. So after ...
Dan Piponi'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
8 votes
3 answers
694 views

Tensor transformation

Consider the following tensor in coordinate basis $T=T^{\mu}_{\nu\lambda} \partial_{\mu}\otimes dx^\nu \otimes dx^\lambda$ in two dimensions with coordinates $x^1 = x$ and $x^2 = y$. We take $T^{\mu}...
fasdgr's user avatar
  • 407
8 votes
2 answers
488 views

How to simplify tensor expression with symbolic coeficients?

I can use Vectors to simplify the following expression: ...
ZHANG Juenjie 's user avatar
8 votes
1 answer
500 views

Compiling Map over expression that yields a ragged array

I'm trying to speed up a function that looks in the neighborhood of each 3D point in a large dataset and finds all the points within 1 unit in each direction, x, y, z. I've started by using ...
s0rce's user avatar
  • 9,632
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
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
8 votes
2 answers
361 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 ...
Chris Django's user avatar
8 votes
1 answer
230 views

Error messages from TensorContract and TensorReduce

I am struggling with a few errors when using symbolic tensors. I am using mathematica 9.0.1.0, linux x86. The following code generates what seems to me an incorrect tensor, this is the smallest ...
Art Gower's user avatar
  • 586
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
7 votes
2 answers
2k views

How to get rid of nested matrices

If I type into Mathematica TensorProduct[IdentityMatrix[2],IdentityMatrix[2]] It gives me a result that has nested matrices. How do I turn that into a normal ...
Paradox's user avatar
  • 301

1
2 3 4 5
11