MathGroup Archive 2009

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

Search the Archive

Re: How to feed a list of xy pairs into Solve to output xyz triplets

  • To: mathgroup at smc.vnet.net
  • Subject: [mg101203] Re: How to feed a list of xy pairs into Solve to output xyz triplets
  • From: Bill Rowe <readnews at sbcglobal.net>
  • Date: Fri, 26 Jun 2009 06:53:53 -0400 (EDT)

On 6/25/09 at 7:13 AM, WDWNORWALK at aol.com (Bill) wrote:

>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.)

Use Map to map Solve to each of the xy coordinate pairs. This is
done as follows:

In[2]:= ({x, y, z} /.
     Solve[{x == First@#, y == Last@#, 6*x + 4*y + z == 1}, {x, y,
       z}]) & /@ list

Out[2]= {{{1, 2, -13}}, {{3, 1, -21}}, {{5, 4, -45}},
    {{6, 3, -47}}, {{2, 5, -31}}}

Here, I set up a pure function with Solve (the {x, y,
z}/.Solve[{x == First@#, y == Last@#, 6*x + 4*y + z == 1}, {x,
y, z}])& part) and mapped it to the elements of list (the /@
part). If you are unfamiliar with this technique you should read
the documentation on pure functions and Map




  • Prev by Date: Re: How to feed a list of xy pairs into Solve to output xyz triplets
  • Next by Date: Re: Plot with x value in Log
  • Previous by thread: Re: How to feed a list of xy pairs into Solve to output xyz triplets
  • Next by thread: InputString dialog with ENTER-key for inserting end of line