Re: How to subtract two sets of data for a ListPlot
- To: mathgroup at smc.vnet.net
- Subject: [mg76764] Re: How to subtract two sets of data for a ListPlot
- From: dimitris <dimmechan at yahoo.com>
- Date: Sun, 27 May 2007 04:48:26 -0400 (EDT)
- References: <f36gb5$9fq$1@smc.vnet.net>
In the same vein In[3]:= ({list1[[#1,1]], list1[[#1,2]] - list2[[#1,2]]} & ) /@ Range[Length[list1]] Out[3]= {{1, 0}, {2, -2}, {3, -6}} In[4]:= Transpose[{list1[[All,1]], list1[[All,2]] - list2[[All,2]]}] Out[4]= {{1, 0}, {2, -2}, {3, -6}} In[19]:= ({#1, (Plus[#1 - #2] & ) @@ {list1[[#1,2]], list2[[#1,2]]}} & ) /@ Range[Length[list1]] Out[19]= {{1, 0}, {2, -2}, {3, -6}} / chuck009 : > Hi all. Suppose I've calculated two sets of lists of the form for example: > > list1={{1,1},{2,2},{3,3}}; > > list2={{1,1},{2,4},{3,9}}; > > What's an efficient way to create a third list with the same x-values but with the y-values subtracted > > newlist={{1,0},{2,-2},{3,-6}}; > > I realize I can manually subtract them in a For-loop, but I'm sure a one-line command using Map or some other construct can be used as well but can't figure it out. > > Thanks!