Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: How to subtract two sets of data for a ListPlot

  • To: mathgroup at smc.vnet.net
  • Subject: [mg76720] Re: How to subtract two sets of data for a ListPlot
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Sat, 26 May 2007 04:36:30 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <f36gb5$9fq$1@smc.vnet.net>

chuck009 wrote:
> 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!
> 

Several possibilities are illustrated below.

In[1]:=
list1 = {{1, 1}, {2, 2}, {3, 3}};
list2 = {{1, 1}, {2, 4}, {3, 9}};

Module[{temp = list2}, temp[[All, 1]] = 0; list1 - temp]

({#1[[1, 1]], #1[[1, 2]] - #1[[2, 2]]} & ) /@ Thread[{list1, list2}]

Transpose[{list1[[All, 1]], (list1 - list2)[[All, 2]]}]

Transpose[{list1[[All, 1]], list1[[All, 2]] - list2[[All, 2]]}]

Out[3]= {{1, 0}, {2, -2}, {3, -6}}

Out[4]= {{1, 0}, {2, -2}, {3, -6}}

Out[5]= {{1, 0}, {2, -2}, {3, -6}}

Out[6]= {{1, 0}, {2, -2}, {3, -6}}

Regards,
Jean-Marc


  • Prev by Date: Re: How to subtract two sets of data for a ListPlot
  • Next by Date: Re: What to do in v. 6 in place of Miscellaneous`RealOnly
  • Previous by thread: Re: How to subtract two sets of data for a ListPlot
  • Next by thread: Re: How to subtract two sets of data for a ListPlot