Re: How to subtract two sets of data for a ListPlot
- To: mathgroup at smc.vnet.net
- Subject: [mg76723] Re: [mg76672] How to subtract two sets of data for a ListPlot
- From: DrMajorBob <drmajorbob at bigfoot.com>
- Date: Sat, 26 May 2007 04:38:03 -0400 (EDT)
- References: <32048085.1180092395107.JavaMail.root@m35>
- Reply-to: drmajorbob at bigfoot.com
list1 = {{1, 1}, {2, 2}, {3, 3}}; list2 = {{1, 1}, {2, 4}, {3, 9}}; Transpose@{list1[[All, 1]], (list1 - list2)[[All, 2]]} {{1, 0}, {2, -2}, {3, -6}} or Transpose@{list1, list2} /. {{a_, b_}, {a_, c_}} :> {a, b - c} {{1, 0}, {2, -2}, {3, -6}} Bobby On Fri, 25 May 2007 05:45:29 -0500, chuck009 <dmilioto at comcast.com> 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! > > -- DrMajorBob at bigfoot.com