Start with the fact that I am a new user of Mathematica, and this is my problem:

I have a complex simbolic matrix A (rectangular, 14x14), and I want to build a matrix from its imagenary and real parts, such as:

{{A_R, -A_I},{A_I, A_R}}//MatrixForm

I have tried that:

ReV[x_] := Refine[Re[x], _Symbol \[Element] Reals]; 
ImV[x_] := Refine[Im[x], _Symbol \[Element] Reals];
expandedMatrix = {{ReV[A], - ImV[A]}, {ImV[A], ReV[A]}};

But this gives me, under MatrixForm, a matrix of matrices, while I just want a single rectangular matrix which I can use as coefficients matrix of a system of linear equations.

Is there a different way to do that?


2 Answers 2

n = 2;
A = Array[x, {n, n}] + I Array[y, {n, n}];
A // MatrixForm
B = ComplexExpand[ArrayFlatten[{{Re[A], -Im[A]}, {Im[A], Re[A]}}]];
B // MatrixForm

$$\left( \begin{array}{cc} x(1,1)+ \mathrm{i} \, y(1,1) & x(1,2)+ \mathrm{i} \, y(1,2) \\ x(2,1)+ \mathrm{i} \, y(2,1) & x(2,2)+ \mathrm{i} \, y(2,2) \\ \end{array} \right)$$

$$\left( \begin{array}{cccc} x(1,1) & x(1,2) & -y(1,1) & -y(1,2) \\ x(2,1) & x(2,2) & -y(2,1) & -y(2,2) \\ y(1,1) & y(1,2) & x(1,1) & x(1,2) \\ y(2,1) & y(2,2) & x(2,1) & x(2,2) \\ \end{array} \right)$$

  • $\begingroup$ As I mentioned, I am new to this program and I don't know the difference between array an matrix. In my code, I have used "DiagonalMatrix" to crate the basic matrix and then I've used "ReplacePart" to put things in other places in the matrix. So your saing I need to change it to array? $\endgroup$
    – SHBR
    Oct 28, 2018 at 11:47
  • $\begingroup$ No need for special treatment: In Mathematica, matrices are simply arrays (or tensors) of tensor rank 2. And arrays are simply nested Lists of list in rectangular shape. $\endgroup$ Oct 28, 2018 at 12:38

I found a simple way to solve the problem by using the function "Join":

Join[Join[Re[A], - Im[A], 2], Join[Im[A], Re[A], 2]] // MatrixForm

"Join[list1,list2]" concatenates in column direction, while "Join[list1,list2,2]" concatenates in row direction.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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