Re: programming in mathematica
- To: mathgroup at smc.vnet.net
- Subject: [mg42410] Re: [mg42389] programming in mathematica
- From: Selwyn Hollis <selwynh at earthlink.net>
- Date: Sat, 5 Jul 2003 03:10:56 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
Hi Laura,
I'm going to assume that in gz^h/(az^b+cz^d+ez^f) the exponents b, d, f
are distinct.
Define the pattern
pat := (g_.*z^h_.)/(a_.*z^b_. + c_.*z^d_. + e_.*z^f_.)
(The dots after the blanks make those bits "optional", defaulting to 1.)
Next define the rule
pick := pat -> {a, b, c, d, e, f, g, h}
Now, for example,
(2*z^3)/(3*z + 7*z^2 - 2*z^5) /. pick
{3, 1, 7, 2, -2, 5, 2, 3}
For a list of such fractions, say,
r := Random[Integer, {1, 9}];
test := Cases[Table[(r*z^r)/(r*z^r + r*z^r + r*z^r), {10}], pat];
just apply the rule to the list:
results = test /. pick
{{3, 5, 3, 6, 6, 7, 7, 9}, {7, 3, 5, 7, 5, 8, 7, 2},
{1, 2, 4, 8, 3, 9, 6, 7}, {1, 2, 5, 7, 9, 9, 1, 8}}
and if you want to add them,
Plus @@ results
{12, 12, 17, 28, 23, 33, 21, 26}
Hope this helps...
-----
Selwyn Hollis
http://www.math.armstrong.edu/faculty/hollis
On Friday, July 4, 2003, at 01:33 AM, Pickard Laura R wrote:
> Hi all,
>
> 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.
>
> Any help would be greatly appreciated.
>
> Thanks,
>
> Laura Pickard.
>
> "This e-mail is intended for the recipient only. If you are not the
> intended recipient you must not use, disclose, distribute, copy, print,
> or rely upon this e-mail. If an addressing or transmission error has
> misdirected this e-mail, please notify the author by replying to this
> e-mail."
>
> "Recipients should note that all e-mail traffic on MOD systems is
> subject to monitoring and auditing."
>
>