Re: How to feed a list of xy pairs into Solve to output xyz triplets
- To: mathgroup at smc.vnet.net
- Subject: [mg101178] Re: [mg101149] How to feed a list of xy pairs into Solve to output xyz triplets
- From: Sseziwa Mukasa <mukasa at jeol.com>
- Date: Fri, 26 Jun 2009 06:48:44 -0400 (EDT)
- References: <200906251113.HAA10623@smc.vnet.net>
On Jun 25, 2009, at 7:13 AM, Bill wrote: > Hi: > > Let's say that I have a list of xy coordinate pairs: > > list= {{1,2}},{3,1},{5,4},{6,3},{2,5}}. > > Now I'd like to find xyz triplets using Solve for the equation 6*x > + 4*y + z == 1. > > xyz results: {{1,2,-13}},{3,1,-21},{5,4,-45},{6,3,-47},{2,5,-31}}. > (I used Solve 5 times.) > > > Question: How do I code that into Mathematica for a "one shot > output?" (Use Solve once.) One approach is to solve for z, then map the solution over the list: Block[{sol=Solve[6*x+4*y+z==1,z][[1]]},Append[#,z/.sol/.{x->#[[1]],y- >#[[2]]}]&/@list] If your equation is linear you can avoid using Solve altogether and just do the matrix arithmetic to get a matrix of z values which you can append to list: Block[{z = Table[1, {Length[list]}] - Flatten[list.{{6}, {4}}]}, ArrayFlatten[{{list, Transpose[{z}]}}]]
- References:
- How to feed a list of xy pairs into Solve to output xyz triplets
- From: Bill <WDWNORWALK@aol.com>
- How to feed a list of xy pairs into Solve to output xyz triplets