0
|
15162 Views
|
4 Replies
|
0 Total Likes
View groups...
Share

# How to multiple a list?

Posted 9 years ago
 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
Sort By:
Posted 9 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 9 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 9 years ago
 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 9 years ago
 . In[1]:= L1 = {{x1, y1}, {x2, y2}, {x3, y3}, {x4, y4}, {xn, yn}}; L2 = Map[{a*First[#], Last[#]} &, L1] Out[2]= {{a x1, y1}, {a x2, y2}, {a x3, y3}, {a x4, y4}, {a xn, yn}} In[3]:= L2 = Map[{a, 1}*# &, L1] Out[3]= {{a x1, y1}, {a x2, y2}, {a x3, y3}, {a x4, y4}, {a xn, yn}} In[4]:= f[v_] := {a*First[v], Last[v]}; L2 = Map[f, L1] Out[5]= {{a x1, y1}, {a x2, y2}, {a x3, y3}, {a x4, y4}, {a xn, yn}} In[6]:= f[v_] := {a, 1}*v; L2 = Map[f, L1] Out[7]= {{a x1, y1}, {a x2, y2}, {a x3, y3}, {a x4, y4}, {a xn, yn}} In[8]:= f[{x_, y_}] := {a*x, y}; L2 = Map[f, L1] Out[9]= {{a x1, y1}, {a x2, y2}, {a x3, y3}, {a x4, y4}, {a xn, yn}} In[10]:= f[{x_, y_}] := {a*x, y}; L2 = f /@ L1 Out[11]= {{a x1, y1}, {a x2, y2}, {a x3, y3}, {a x4, y4}, {a xn, yn}} In[12]:= L2 = Transpose[{a*First[Transpose[L1]], Last[Transpose[L1]]}] Out[12]= {{a x1, y1}, {a x2, y2}, {a x3, y3}, {a x4, y4}, {a xn, yn}} In[13]:= t = Transpose[L1]; L2 = Transpose[{a*First[t], Last[t]}] Out[14]= {{a x1, y1}, {a x2, y2}, {a x3, y3}, {a x4, y4}, {a xn, yn}} In[15]:= L2 = L1; For[i = 1, i <= Length[L1], i++, L2[[i, 1]] = a*L2[[i, 1]] ]; L2 Out[17]= {{a x1, y1}, {a x2, y2}, {a x3, y3}, {a x4, y4}, {a xn, yn}} It seems like there should be a simple way to use the AffineTransform function to accomplish this.