Re: get a, b from numbers in the form a+b Pi
- To: mathgroup at smc.vnet.net
- Subject: [mg119195] Re: get a, b from numbers in the form a+b Pi
- From: Murray Eisenberg <murray at math.umass.edu>
- Date: Tue, 24 May 2011 05:59:54 -0400 (EDT)
All the solutions below work provided each number in nums includes both a nonzero a and a nonzero b. But all fails otherwise! On 5/23/2011 6:22 AM, Bob Hanlon wrote: > 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}; > > nums /. {Plus -> List, Pi -> 1} Fails if List nums includes 2 or Pi or 3Pi, for example. > > > (List @@@ Expand[nums]) /. Pi -> 1 Fails if List nums includes 2, for example, or Pi. > > > {#[[1]], #[[2]]/Pi}& /@ Expand[nums] Error if List nums includes, say, 2. > > > #/{1, Pi}& /@ (List @@@ Expand[nums]) > Fails if List nums includes 2, for example, or Pi. > > ---- "1.156"<rob at piovere.com> wrote: > > ============= > 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 -- Murray Eisenberg murray at math.umass.edu Mathematics & Statistics Dept. Lederle Graduate Research Tower phone 413 549-1020 (H) University of Massachusetts 413 545-2859 (W) 710 North Pleasant Street fax 413 545-1801 Amherst, MA 01003-9305