0
$\begingroup$

if i have two columnar matrices A,B . then how can i merge both matrices into a row matrix.

         A =  {-0.157681 - 0.0140601 I, 0.987384 + 0. I, 0.0000372277 - 0.00334827 I,-0.000272331 + 0.000439789 I}  ;
         B =  {0.991357 + 0. I, -0.130103 - 0.0163991 I, -0.000272562 + 0.000624515 I, 0.0000254395 - 0.00390685 I } ;
         Matrix = ( {{A, B}} )

Which gives me output enter image description here

i want to know how to remove the brackets inside the matrix. and i also want to know whether removing of these brackets effect the matrix.? Thanks in advance

$\endgroup$
8
  • 1
    $\begingroup$ Have you seen Join[]? $\endgroup$ Nov 20, 2015 at 14:31
  • $\begingroup$ yes you are right dear , but Join [ A,B,2]; will solve it but , i want to some other methods $\endgroup$
    – M.M Umber
    Nov 20, 2015 at 14:36
  • 1
    $\begingroup$ Then you should have mentioned it in your question to begin with, bub. $\endgroup$ Nov 20, 2015 at 14:37
  • $\begingroup$ You can use Transpose[Flatten/@{A,B}], and I'm sure we could come up with an infinite number of convoluted variations. But why do you not want to use the method J.M. gave? If you have a particular performance goal in mind you might get better answers. $\endgroup$
    – N.J.Evans
    Nov 20, 2015 at 14:50
  • 2
    $\begingroup$ LMAO @ bub. I can't help but notice you asked this question 2 hours ago and got two workable solutions in the comments $\endgroup$
    – Jason B.
    Nov 20, 2015 at 14:51

1 Answer 1

3
$\begingroup$
A = ({{-0.157681 - 0.0140601 I}, {0.987384 + 0. I}, {0.0000372277 - 
      0.00334827 I}, {-0.000272331 + 0.000439789 I}});
B = ({{0.991357 + 0. I}, {-0.130103 - 0.0163991 I}, {-0.000272562 + 
      0.000624515 I}, {0.0000254395 - 0.00390685 I}});

This is a good point to say that working with column vectors in Mathematica is more trouble than it is worth - you just don't need to do it most of the time. If your A and B were normal row vectors, then all you need is Transpose[{A,B}]. Here are ways that you can work with these column vectors to make a matrix.

Join[A, B, 2] // MatrixForm
ArrayFlatten[{{A, B}}] // MatrixForm
Transpose[Flatten /@ {A, B}] // MatrixForm
Thread[Flatten /@ {A, B}] // MatrixForm

enter image description here

And then, if you want to do it the old-timey way (this is how it feels when I have to work in Fortran)

AB = ConstantArray[0.0, {4, 2}];
For[i = 1, i <= 4, i++,
  AB[[i, 1]] = A[[i, 1]];
  AB[[i, 2]] = B[[i, 1]];
  ];
AB // MatrixForm

enter image description here

$\endgroup$
4
  • $\begingroup$ Jason B Thanks for this value able but my input occur with single bracket around A,B. $\endgroup$
    – M.M Umber
    Nov 20, 2015 at 15:14
  • $\begingroup$ Please Jason B see it again $\endgroup$
    – M.M Umber
    Nov 20, 2015 at 15:21
  • $\begingroup$ And so how is Transpose[{A, B}] not working for you? $\endgroup$
    – Jason B.
    Nov 20, 2015 at 15:24
  • $\begingroup$ :P it works Thanks a lot Dear $\endgroup$
    – M.M Umber
    Nov 20, 2015 at 15:26

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