Message Boards Message Boards

0
|
8250 Views
|
6 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Matrix Operations help!!

Posted 10 years ago

Hello everyone,

I want to construct a M X N matrix with results imported from other matrices.

For example, I have 3 matrices enter image description hereenter image description hereenter image description here

I want to construct a matrix with first column input as A+B, second column as B+C and third column as C+A

Yellow ----> Yellow column as A+B, Orange column as B+C, Blue column as C+A

Basically I want a matrix of all possible combinations. Please help me. Thank you.

Regards,

Azhar Uddin Mohammed

6 Replies

Try http://reference.wolfram.com/language/ and enter the function name in the search documentation field.

POSTED BY: Bruce Miller

I don't know if this will make the ideas more clear, but you could just replace my first two lines with

vecs = {A,B,C};

where A, B, and C are as you defined them in your example.

POSTED BY: Daniel Lichtblau

Partition[vecs, 2, 1, 1, vecs]

Transpose[pairs, {1, 3, 2}]

Sir, can you please explain me what these functions mean? :)

Here is a programmatic step-by-step approach. Possibly there are shorter routes though.

In[1]:= f[a_] := Array[a, 3]
vecs = f /@ {a, b, c}

Out[2]= {{a[1], a[2], a[3]}, {b[1], b[2], b[3]}, {c[1], c[2], c[3]}}

In[6]:= pairs = Partition[vecs, 2, 1, 1, vecs]

Out[6]= {{{a[1], a[2], a[3]}, {b[1], b[2], b[3]}}, {{b[1], b[2], 
   b[3]}, {c[1], c[2], c[3]}}, {{c[1], c[2], c[3]}, {a[1], a[2], 
   a[3]}}}

In[24]:= tpairs = Transpose[pairs, {1, 3, 2}]

Out[24]= {{{a[1], b[1]}, {a[2], b[2]}, {a[3], b[3]}}, {{b[1], 
   c[1]}, {b[2], c[2]}, {b[3], c[3]}}, {{c[1], a[1]}, {c[2], 
   a[2]}, {c[3], a[3]}}}

In[25]:= cols = Apply[Plus, tpairs, {2}]

Out[25]= {{a[1] + b[1], a[2] + b[2], a[3] + b[3]}, {b[1] + c[1], 
  b[2] + c[2], b[3] + c[3]}, {a[1] + c[1], a[2] + c[2], a[3] + c[3]}}

In[26]:= colmat = Transpose[cols]

Out[26]= {{a[1] + b[1], b[1] + c[1], a[1] + c[1]}, {a[2] + b[2], 
  b[2] + c[2], a[2] + c[2]}, {a[3] + b[3], b[3] + c[3], a[3] + c[3]}}
POSTED BY: Daniel Lichtblau

Thank you sir. Your approach appears to be closest to my problem. But hardly I could understand anything because I am new user for Mathematica. I would be glad if you could write the code showing numerical computations for the example I considered. It would give me an idea and help me understand Mathematica to write it for larger matrices. Thank you. :)

Posted 10 years ago

Well, I'm not sure if it's the best, but was this what you were after? {a + b, b + c, c + a} // Transpose // MatrixForm

...hmm... although, in that form, you can't perform things like taking the Determinant on the result. However, this way you can: {a + b, b + c, c + a}[[All, All, 1]] // Transpose // MatrixForm

POSTED BY: Philip Parsons
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract