5
$\begingroup$

Given two matrices $A$ and $B$:

enter image description here

What transformation needs to be applied to transform matrix $A$ into matrix $B$?

A = {{0, c, b, -c + b c, a c, -a + a b, c + b c, a c, a + a b}, {0, c,
    b, c + b c, a c, a + a b, -c + b c, a c, -a + a b}, {0, -1, 0, b, 
   a, 0, b, a, 0}}

B = {{0, c, b, 0, c, b, 0, -1, 0}, {-c + b c, a c, -a + a b, c + b c, 
    a c, a + a b, b, a, 0}, {c + b c, a c, a + a b, -c + b c, 
    a c, -a + a b, b, a, 0}};

EDIT:

I found one method that only uses $\frac{dQ}{d\boldsymbol{\theta}}$, and the result is the same as direct differentiation $\frac{dQ^T}{d\boldsymbol{\theta}}$. The disadvantage of this method is the need to glue the matrix again. Maybe I can get around this with some kind of unified tensor operation ? To immediately receive the entire matrix, without additional gluing.

Rx = RotationMatrix[\[Phi][t], {1, 0, 0}];

Ry = RotationMatrix[\[Xi][t], {0, 1, 0}];

Rz = RotationMatrix[\[Psi][t], {0, 0, 1}];

Q = Rz.Ry.Rx;

v = {\[Phi][t], \[Xi][t], \[Psi][t]};

T1 = Flatten /@ D[Q, {v}];

T2 = Flatten /@ D[Transpose[Q], {v}];

P1 = {{1, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 1, 0, 0, 0, 0, 0}, {0, 0,
     0, 0, 0, 0, 1, 0, 0}, {0, 1, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 
    1, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 1, 0}, {0, 0, 1, 0, 0, 0, 0,
     0, 0}, {0, 0, 0, 0, 0, 1, 0, 0, 0}, {0, 0, 0, 0, 0, 0, 0, 0, 1}};

A1 = T1.{{1, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 1, 0}, {0, 0, 0}, {0, 0,
      0}, {0, 0, 1}, {0, 0, 0}, {0, 0, 0}};

A2 = T1.{{0, 0, 0}, {1, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 1, 0}, {0, 0,
      0}, {0, 0, 0}, {0, 0, 1}, {0, 0, 0}};

A3 = T1.{{0, 0, 0}, {0, 0, 0}, {1, 0, 0}, {0, 0, 0}, {0, 0, 0}, {0, 1,
      0}, {0, 0, 0}, {0, 0, 0}, {0, 0, 1}};

Transpose[P1.ArrayFlatten[{{A1}, {A2}, {A3}}]] == 
   Flatten /@ D[Transpose[Q], {v}] // MatrixForm;
$\endgroup$
3
  • 1
    $\begingroup$ LinearSolve[A, B]? $\endgroup$
    – Lukas Lang
    Jul 23 at 11:03
  • $\begingroup$ @LukasLang please, form your comment as answer $\endgroup$
    – dtn
    Jul 23 at 11:05
  • $\begingroup$ @LukasLang looking at the matrices I have an assumption about permutation matrices, am I right? if so, what will they look like? $\endgroup$
    – dtn
    Jul 23 at 11:06
7
$\begingroup$
B == ArrayReshape[Transpose[ArrayReshape[A, {3, 3, 3}]], {3, 9}]

True

Also, in loop style:

result = ConstantArray[0, {3, 9}];
Do[
  result[[i, 3 (j - 1) + k]] = A[[j, 3 (i - 1) + k]], 
  {i, 1, 3}, 
  {j, 1, 3}, 
  {k, 1, 3}
];
result == B

True

Or with a permutation matrix of size $27 \times 27$:

P = Block[{A, B, a},
   A = Array[a, {3, 9}];
   B = ArrayReshape[Transpose[ArrayReshape[A, {3, 3, 3}]], {3, 9}];
   SparseArray[D[Flatten[B], {Flatten[A], 1}]]
   ];

ArrayReshape[P.Flatten[A], Dimensions[B]]
$\endgroup$
9
  • $\begingroup$ Thank you! is it possible to formalize your proposed operation? Express it as a formula? As I assumed, you are using a permutation. $\endgroup$
    – dtn
    Jul 23 at 12:17
  • 1
    $\begingroup$ Well, if you treat both matrices as 3-tensors ArrayReshape[A, {3, 3, 3}] and ArrayReshape[B, {3, 3, 3}], then it is just about permuting the first two slots of the tensors. $\endgroup$ Jul 23 at 12:18
  • $\begingroup$ I mean the following. Find such a matrix $X$, or a pair of matrix $x$ and $X$ for example (I don't know exactly how many are needed), so that either $AX=B$ or $xAX=B$. $\endgroup$
    – dtn
    Jul 23 at 12:26
  • 1
    $\begingroup$ Hm. You certainly cannot do that if you require that both x and X are permutation matrices; this can be seen when you compare the two columns in A and B that contain the -1. $\endgroup$ Jul 23 at 12:37
  • 1
    $\begingroup$ Not sure what you need this for. Is it about coding? Just in case that you mean to code that in C, C++ or whatever: note that dense matrices and arrays are stored in flattened form. So the permutation matrix P from my post, applied to the raw buffer of A would do what you want. $\endgroup$ Jul 23 at 12:49
7
$\begingroup$

You can use LinearSolve to find one possible matrix such that A.X==B:

X = LinearSolve[A, B];
A.X == B // FullSimplify
(* True *)
$\endgroup$
8
  • $\begingroup$ The result is a matrix $X$? $\endgroup$
    – dtn
    Jul 23 at 11:08
  • $\begingroup$ @dtn Yes, X is a 9x9 matrix. If you are looking for another kind of "transformation", you'll have to be a bit more specific with your requirements. (When talking about transformations in the context of matrixes, the usual thing that's meant is a transformation matrix such as the X from the answer) $\endgroup$
    – Lukas Lang
    Jul 23 at 11:17
  • $\begingroup$ Thank you for your answer. I understand what you are talking about. At the moment, for my tasks there is only one requirement that transformations lie in the class of vector-matrix operations. But I will happily explore possible alternatives if you point me to the sources. $\endgroup$
    – dtn
    Jul 23 at 11:27
  • 1
    $\begingroup$ I don't think this can be done purely using permutation matrices and dot products. You need to allow some other operations for this to be possible $\endgroup$
    – Lukas Lang
    Jul 23 at 13:04
  • 1
    $\begingroup$ @dtn As far as I can tell, no such permutation matrices exist (assuming a permutation matrix is a matrix where each row/column has exactly one 1 and the rest is 0). A matrix product with such a matrix can only ever permute rows/columns, but that is not sufficient to perform the permutation you are after. $\endgroup$
    – Lukas Lang
    Jul 23 at 19:27
1
$\begingroup$

Here is a solution using Part

Flatten[A[[All, # ;; ;; 3]] & /@ Range@3 // Transpose, 1] // Transpose
$\endgroup$
2
  • $\begingroup$ math.stackexchange.com/a/4201431/656085 Please see the very end of the answer. I need something similar, but I don't know the structure of the $P_{9\times9}$ and $P_{3\times3}$ matrices. $\endgroup$
    – dtn
    Jul 23 at 15:32
  • $\begingroup$ See my edit please. I found a variant of the way how to switch to the transposed matrix through the original one. $\endgroup$
    – dtn
    Jul 23 at 19:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.