Group Abstract Group Abstract

Message Boards Message Boards

Multiplying lists

Given the two lists; how do you multiply them? L1 = {{X1 , y1}, {X2 , y2}, {X3 , y3}, {X4, y4},………...,{Xn, yn}} L2 = {{X1 , z1}, {X2 , z2}, {X3 , z3}, {X4, z4},…………,,{Xn, zn}} To obtain: L1L2 = {{ X1 , y1 z1}, { X2 , y2* z2}, { X3 , y3* z3}, { X4 , y4* z4},……………},{Xn, yn*zn}

Attachments:
6 Replies

I tried it for "n=500" and it worked. I was just unsure. Many thanks !!!!!!!!!!!!!!!!!!!!!!!!!!!!

You always a good job

sorry. missed the answer:

In[57]:= Transpose[{Transpose[L1][[1]], 
  Transpose[L1][[2]] Transpose[L2][[2]]}]

Out[57]= {{X1, y1 z1}, {X2, y2 z2}, {X3, y3 z3}, {X4, y4 z4}}
POSTED BY: Hans Dolhaine

Can this result be extended for "n" elements as:

Given the two lists; how do you multiply them? L1 = {{X1 , y1}, {X2 , y2}, {X3 , y3}, {X4, y4},………...,{Xn, yn}} L2 = {{X1 , z1}, {X2 , z2}, {X3 , z3}, {X4, z4},…………,},{Xn, zn}} To obtain: L1L2 = {{ X1 , y1 z1}, { X2 , y2* z2}, { X3 , y3* z3}, { X4 , y4* z4},……………},{Xn, yn*zn}

Yes. Just try it.

But note, the code given by Sean Clarke,

Transpose[{L1[[All, 1]], L1[[All, 2]]*L2[[All, 2]]}]

which is basically the same, looks a bit mor elegant.

Regards HD

POSTED BY: Hans Dolhaine

I

n[52]:= L1 = {{X1, y1}, {X2, y2}, {X3, y3}, {X4, y4}}
 L2 = {{X1, z1}, {X2, z2}, {X3, z3}, {X4, z4}} 

Out[52]= {{X1, y1}, {X2, y2}, {X3, y3}, {X4, y4}}

Out[53]= {{X1, z1}, {X2, z2}, {X3, z3}, {X4, z4}}

will do it. regards

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