Re: get a, b from numbers in the form a+b Pi
- To: mathgroup at smc.vnet.net
- Subject: [mg119173] Re: get a, b from numbers in the form a+b Pi
- From: Peter Pein <petsie at dordos.net>
- Date: Mon, 23 May 2011 06:29:16 -0400 (EDT)
- References: <iraq88$ls8$1@smc.vnet.net>
Am 22.05.2011 12:58, schrieb 1.156: > I have lists of numbers (Mathematica output) all numerically in the > form a + b*Pi and I'm trying to extract the values of a and b for > further work. > > Here's an example of the best I've been able to do so far: > > nums={1/2 (-2+\[Pi]),-2+(3 \[Pi])/4,-(11/3)+(5 \[Pi])/4,5/48 (-64+21 > \[Pi]),-(61/5)+(63 \[Pi])/16,-(338/15)+(231 \[Pi])/32}; > {FullForm[#][[1,1]],FullForm[#][[1,2]]/\[Pi]}&/@nums > > When I run this line of code 4 of the six input numbers give me the > {a,b} I'm looking for but the first and fourth entries fail because the > form isn't right. Possibly I could patch this scheme to look for a small > finite set of possibilities of input number form but I suspect I may a > long way from attacking this problem correctly. > > Can someone offer some other ideas on how to pull this off? Many thanks > for looking at this. Rob expanding the list nums might help (also adding some special cases): Expand[Join[nums,{0,1,Pi}]]/.{x_?NumericQ/;FreeQ[x,Pi]:>{x,0},a_. +b_. Pi:>{a,b}} gives: {{-1,1/2},{-2,3/4},{-(11/3),5/4},{-(20/3),35/16},{-(61/5),63/16},{-(338/15),231/32},{0,0},{1,0},{0,1}} hth, Peter