Message Boards Message Boards

How to multiple a list?

Given: L1 = {{x1,y1},{x2,y2},{x3,y3},{x4,y4},...........{xn,yn}}: how is L2 below, obtain:

L2 = {{ax1,y1},{ax2,y2},{ax3,y3},{ax4,y4}.....{axn,yn}}

4 Replies
Posted 10 years ago

Or

In[1]:= {a, 1} # & /@ {{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}}

Out[1]= {{a x1, y1}, {a x2, y2}, {a x3, y3}, {a x4, y4}}

(Short notation for In6 in Bill Simpson's list.)

POSTED BY: David Keith
Posted 10 years ago

Another solution which makes use of a delayed rule:

In[1]:= L1 = {{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}, {xn, yn}};
L2 = L1 /. {x_, y_} :> {a x, y}

Out[2]= {{a x1, y1}, {a x2, y2}, {a x3, y3}, {a x4, y4}, {a xn, yn}}
POSTED BY: Xavier Roy
In[1]:= Transpose[{a, 1} Transpose[{{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}, {x5, y5}, {xn, yn}}]]
Out[1]= {{a x1, y1}, {a x2, y2}, {a x3, y3}, {a x4, y4}, {a x5, y5}, {a xn, yn}}
POSTED BY: Udo Krause
Posted 10 years ago
POSTED BY: Bill Simpson
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