Re: Changing only Y's in a list of points: How?
- To: mathgroup at smc.vnet.net
- Subject: [mg6693] Re: Changing only Y's in a list of points: How?
- From: Yaroslaw Bazaliy <yar at leland.stanford.edu>
- Date: Fri, 11 Apr 1997 01:49:49 -0400 (EDT)
- Organization: Stanford University
- Sender: owner-wri-mathgroup at wolfram.com
David S. Pieczkiewicz wrote: > > Hopefully, the subject line says it all. If not, here's what I'm trying > to do. Suppose I have a list of points: > > pointlist = { {x1,y1}, {x2,y2}, {x3,y3}, ..., {xn,yn} }; > > Of course, there are numbers instead of the above symbols, but you get > the picture. Now, suppose I'd like to "raise" or "lower" this list, in > effect, changing all the y's by a constant, but leaving the x's alone. I would to it this way: In[1]:= l={{x1,y1},{x2,y2},{x3,y3},{x4,y4},{x5,y5}} Out[1]= {{x1,y1},{x2,y2},{x3,y3},{x4,y4},{x5,y5}} In[2]:= m=Transpose[l] Out[2]= {{x1,x2,x3,x4,x5},{y1,y2,y3,y4,y5}} In[3]:= n={m[[1]],m[[2]]+u} Out[3]= {{x1,x2,x3,x4,x5},{u+y1,u+y2,u+y3,u+y4,u+y5}} In[4]:= newl=Transpose[n] Out[4]= {{x1,u+y1},{x2,u+y2},{x3,u+y3},{x4,u+y4},{x5,u+y5}} And then you can combine the four steps in one: newl = Transpose[ {Transpose[l][[1]], Transpose[l][[2]] + u} ] Yaroslaw.