MathGroup Archive 2003

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

Search the Archive

Re: programming in mathematica

  • To: mathgroup at smc.vnet.net
  • Subject: [mg42414] Re: programming in mathematica
  • From: bobhanlon at aol.com (Bob Hanlon)
  • Date: Sat, 5 Jul 2003 03:10:59 -0400 (EDT)
  • References: <be33io$a7g$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

This approach could be streamlined if the powers must be positive  integers.

coef[expr_, var_Symbol:z] := Module[{n=Numerator[expr], d=Denominator[expr]},
      DeleteCases[Flatten[{Cases[1+d, a_*var^b_. :> {a,b}],
            {{DeleteCases[1+d, a_*var^b_.]-1,0}},
            Cases[1+n, a_*var^b_. :> {a,b}],
            {{DeleteCases[1+n, a_*var^b_.]-1,0}}},1],{0,0}]];

rbe[cl_List, var_Symbol:z] := 
    Module[{terms=#[[1]]*var^#[[2]]& /@ cl},
      Last[terms]/(Plus@@Drop[terms,-1])];

expr=g*z^h/(a*z^b+c*z^d+e*z^f);

coef[expr]

{{a, b}, {c, d}, {e, f}, {g, h}}

expr==rbe[%]

True

Using x as the variable rather than z:

expr=g/(a*x^b+c*x^d+e*x^f);

coef[expr,x]

{{a, b}, {c, d}, {e, f}, {g, 0}}

expr==rbe[%,x]

True

expr=g*z^h/(a*z^b+c*z^d+e);

coef[expr]

{{a, b}, {c, d}, {e, 0}, {g, h}}

expr==rbe[%]

True

expr=g/(a*z^b+c*z^d+e);

coef[expr]

{{a, b}, {c, d}, {e, 0}, {g, 0}}

expr==rbe[%]

True

expr=3*z^2/(7*z^(1/2)+6*z+9*z^(-1));

coef[expr]

{{9, -1}, {7, 1/2}, {6, 1}, {3, 2}}

expr==rbe[%]

True


Bob Hanlon

In article <be33io$a7g$1 at smc.vnet.net>, Pickard Laura R
<LRPICKARD at mail.dstl.gov.uk> wrote:

<< I cannot view the newsgroup as I am stuck behind a firewall here, but if you
could email me any help with this, it would be much appreciated.

I am new to using mathematica (currently I have version 4.1, should be
getting a trial copy of version 5 soon, my os is winNT).  I have been
attempting to do some programming and need to automate a calculation, to be
done far too many times to attempt it manually.  

A previous calculation outputs a sum of fractions in terms of z, all are of
the form gz^h/(az^b+cz^d+ez^f).  I need to do a calculation involving the
numbers a-h.  I would like to be able to input the fraction, automatically
assign the correct numbers from it to the variables a-h, then do the
calculation and output the result.  Ideally, if I could input the sum of all
the fractions directly as output from the previous calculation and do this
for each one, then output an answer which is the sum of the results for each
fraction that would be best.  I have found my way around programming in
basic functions, but am unsure as to how to input a standard form of
equation and automatically assign the values to the variables for
calculation.  
 >><BR><BR>


  • Prev by Date: Re: A puzzle for Mathematica
  • Next by Date: Re: programming in mathematica
  • Previous by thread: Re: programming in mathematica
  • Next by thread: Re: programming in mathematica