MathGroup Archive 2010

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How to concatenate matrices?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg113097] Re: How to concatenate matrices?
  • From: Sseziwa Mukasa <mukasa at jeol.com>
  • Date: Wed, 13 Oct 2010 12:38:49 -0400 (EDT)
  • References: <201010121749.NAA03450@smc.vnet.net>

On Oct 12, 2010, at 1:49 PM, Eduardo M. A. M.Mendes wrote:

> Hello
>
>
>
> Although I read the help on matrices, I could not figure out how to
> concatenate two matrices.
>
>
>
> What I have is:
>
>
>
> B1 - (vector) - as a result of P21.x1 (product of a matrix and a 
vector)
>
> B2 - (vector) - as a result of P22.x2
>
>
>
> B=[B1,B2]  -  that is, a matrix with two columns.
>
>
>
> Join, Append, and all sort of funny functions return even funnier 
results
> (elements with {}). 

If x1 and x2 are 1 dimensional lists then B1 and B2 are not columns, 
they are one dimensional and so do not possess columns or rows, only 
length.  You can form column vectors out of B1 and B2 by giving them an 
extra dimension then transposing so the length is the number of rows of 
the result, eg. Transpose[{B1}].  From there you can use the 
ArrayFlatten function:

ArrayFlatten[{{Transpose[{B1}],Transpose[{B2}]}}]

A shorthand for understanding all the braces in ArrayFlatten is that is 
joins the rows of arrays at level 2 and the columns of arrays at level 
1, so to join the rows of B1 and B2 we need to put them at level 2.

Alternatively, you can make a function that takes elements at the same 
position in B1 and B2 and returns a list of those elements.  Mapping 
this function over the two will result in a two column matrix:

MapThread[{#, #2}&,{B1,B2}]

If B1 and B2 are actual column matrices: eg. Dimensions[B1] is a list of 
two values, the second of which is 1 then you can use ArrayFlatten but 
omit the Transpose:

ArrayFlatten[{{B1,B2}}]

Regards,
	Ssezi




  • Prev by Date: Re: something nice I found today, return multiple values from a function
  • Next by Date: Re: Limitations of Minimize? Time to buy a new PC for Mathematica?
  • Previous by thread: How to concatenate matrices?
  • Next by thread: Re: How to concatenate matrices?