Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #2684

Re: get a, b from numbers in the form a+b Pi

From Murray Eisenberg <murray@math.umass.edu>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: get a, b from numbers in the form a+b Pi
Date 2011-05-24 10:00 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <irfvk6$c0e$1@smc.vnet.net> (permalink)

Show all headers | View raw


The code

   Expand[nums] /. a_ + b_ Pi :>  {a, b}

fails in case nums includes, e.g., entries 2, Pi, or 3 Pi.

On 5/23/2011 6:25 AM, Bill Rowe wrote:
> On 5/22/11 at 6:57 AM, rob@piovere.com (1.156) 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
>
> This seems to work:
>
> In[11]:= Expand[nums] /. a_ + b_ Pi :>  {a, b}
>
> Out[11]= {{-1, 1/2}, {-2, 3/4}, {-(11/3), 5/4}, {-(20/3), 35/16},
>      {-(61/5), 63/16}, {-(338/15), 231/32}}
>
>

-- 
Murray Eisenberg                     murray@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

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

Re: get a, b from numbers in the form a+b Pi Murray Eisenberg <murray@math.umass.edu> - 2011-05-24 10:00 +0000

csiph-web