3

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 their into a single operation in such a way that I get a matrix of the following form:

$\boldsymbol{L}=\begin{bmatrix}L_1 & 0 & 0\\0 & L_2 & 0\\0 & 0 & L_3\end{bmatrix}$

I'm assuming this can be done using a tensor operation as well as combining vectors into a matrix. Probably, something like that:

$\boldsymbol{L} \approx ? \boldsymbol{u}^T\boldsymbol{J}\boldsymbol{u}$ or $\boldsymbol{L} \approx \boldsymbol{u}^T \otimes ? \boldsymbol{J} \otimes ? \boldsymbol{u}$

But the problem turned out to be that, firstly, my $J$-matrices are different, and secondly, there are side off-diagonal elements in the result.So far, I haven't come up with a suitable operation.

TensorProduct[{Subscript[u, 1], Subscript[u, 2], Subscript[u, 3]}, 
 TensorProduct[{Subscript[u, 1], Subscript[u, 2], Subscript[u, 
   3]}, {J}]]

I need help and advice. Thank you for attention!

dtn
  • 2,394
  • 2
  • 8
  • 18
  • 1
    My deleted answer did not answer the question. You are asking for a 3x3 matrix with the quadratic forms on the the diagonal. My "answer" had $J_1$, $J_2$, $J_3$ on the diagonal, not the $L_i$'s. Sorry for the confusion. – LouisB Apr 11 '22 at 06:21
  • @LouisB never mind :) we'll think of something – dtn Apr 11 '22 at 06:31
  • Might this help? https://mathematica.stackexchange.com/a/153181/35390 Constructing block-diagonal matrices this way also works for non-square matrices. – JEM_Mosig Apr 11 '22 at 07:06

2 Answers2

2

I am not sure if I understand the question correctly, but if what you want is to produce a block diagonal matrix from a list of u's and a list of J's then

us = {u1, u2, u3};
Js = {J1, J2, J3};
DD = DiagonalMatrix[Inner[Dot, us, Inner[Dot, Js, us, List], List]]

will produce

{{u1 . J1 . u1, 0, 0}, {0, u2 . J2 . u2, 0}, {0, 0, u3 . J3 . u3}}

as you want. It also works if the u's are Arrays of length n and the J's are nxn matrices. If you prefer to work with nx1 matrices then you will need to transpose the us in the outer Inner.

If you already have the L's then DiagonalMatrix is all you need.

Mauricio de Oliveira
  • 2,001
  • 13
  • 15
  • In general, yes, you correctly caught my question. And I understand that, apparently, it is clearly possible to come up with more than one such ways. I will consider your option, just write, please, the formula by which this problem is solved. – dtn Apr 11 '22 at 14:12
  • That would be DiagonalMatrix[Inner[Dot, us, Inner[Dot, Js, us, List], List]]. Or do you still have something that needs to be addressed? – Mauricio de Oliveira Apr 11 '22 at 20:36
  • Yes, please, write your line in the form of a mathematical formula. – dtn Apr 12 '22 at 05:26
  • 1
    This line is the formula: it is applying an inner product in which multiplication is Dot and sum is List twice, followed by the structural operation DiagonalMatrix that takes a list into a diagonal matrix. – Mauricio de Oliveira Apr 12 '22 at 13:58
1

First define the ui and ji using helper functions:

u[i_] := {Subscript[u, i, 1], Subscript[u, i, 2], Subscript[u, i, 3]}
{u1, u2, u3} = u /@ {1, 2, 3};
j[i_] := Table[Subscript[j, i, i1, i2], {i1, 3}, {i2, 3}];
{j1, j2, j3} = j /@ {1, 2, 3};

Now it is easy to create the final matrix:

mat={{u1 . j1 . u1, 0, 0}, {0, u2 . j2 . u2, 0}, {0, 0, u3 . j3 . u3}};
mat // MatrixForm

enter image description here

Addendum

If you want to create the matrix automatically instead by hand, you may write:

DiagonalMatrix[
 MapThread[#1 . #2 . #1 &, {{u1, u2, u3}, {j1, j2, j3}}]] 
Daniel Huber
  • 51,463
  • 1
  • 23
  • 57
  • Daniel, yes, this method works. But the matrix is constructed forcibly, i.e. has the desired structure forcibly. I would like to get the same matrix, but using tensors, or possibly outer and inner products, probably... As suggested in another answer in this thread. – dtn Apr 11 '22 at 16:39
  • I added the code to create the diagonal matrix by code. – Daniel Huber Apr 11 '22 at 16:59