# 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 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!

• 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. Apr 11, 2022 at 6:21
• @LouisB never mind :) we'll think of something
– dtn
Apr 11, 2022 at 6:31
• Might this help? mathematica.stackexchange.com/a/153181/35390 Constructing block-diagonal matrices this way also works for non-square matrices. Apr 11, 2022 at 7:06

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.

• 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, 2022 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? Apr 11, 2022 at 20:36
• Yes, please, write your line in the form of a mathematical formula.
– dtn
Apr 12, 2022 at 5:26
• 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. Apr 12, 2022 at 13:58

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 DiagonalMatrix[