[Date Index]
[Thread Index]
[Author Index]
RE: A Functional Programming Question
*To*: mathgroup at smc.vnet.net
*Subject*: [mg24746] RE: [mg24705] A Functional Programming Question
*From*: Wolf Hartmut <hwolf at debis.com>
*Date*: Wed, 9 Aug 2000 02:31:54 -0400 (EDT)
*Sender*: owner-wri-mathgroup at wolfram.com
> -----Original Message-----
> From: David Park [SMTP:djmp at earthlink.net]
To: mathgroup at smc.vnet.net
> Sent: Saturday, August 05, 2000 1:02 AM
> To: BobHanlon at aol.com; andrzej at tuins.ac.jp; Johannes Ludsteck; Allan
> Hayes; Hartmut Wolf; MathGroup; Paul J. Hinton; linsuain+ at andrew.cmu.edu
> Subject: RE: [mg24705] A Functional Programming Question
>
> Thanks everybody for the replies.
>
> I zeroed in on two of them, the one by Johannes Ludsteck and the one by
> Allan Hayes because they seemed to be adaptable to a more general parallel
> manipulation of equations.
>
> Here is a somewhat more general set of parallel equations:
>
> eqns = {(a1 x + b1)/c1 == 0, (a2 y + b2)/c2 == 0, (a3 z + b3)/c3 == 0};
>
> Suppose that we wish to solve for the square roots of x, y and z.
>
> Here is a routine which is an adaptation of Johannes method:
>
> parallelmap[eqns_, op_, parms_] :=
> MapThread[
> Function[parm, Function[eq, op[#, parm] & /@ eq]][#2][#1] &, {eqns,
> parms}]
>
> We can now manipulate the equations in parallel, step-by-step.
>
> parallelmap[eqns, #1#2 &, {c1, c2, c3}]
> parallelmap[%, #1 - #2 &, {b1, b2, b3}]
> parallelmap[%, #1/#2 &, {a1, a2, a3}]
> parallelmap[%, Sqrt[#] &, {d, d, d}]
>
> {b1 + a1 x == 0, b2 + a2 y == 0, b3 + a3 z == 0}
> {a1 x == -b1, a2 y == -b2, a3 z == -b3}
> {x == -(b1/a1), y == -(b2/a2), z == -(b3/a3)}
> {Sqrt[x] == Sqrt[-(b1/a1)], Sqrt[y] == Sqrt[-(b2/a2)],
> Sqrt[z] == Sqrt[-(b3/a3)]}
>
> The last step works because the function only looks for one argument and
> we
> can just put in dummy values for the second argument. Using Sqrt instead
> of
> Sqrt[#]& will not work.
>
> Working with Allan Hayes method, I came up with this routine:
>
> parallelmap2[eqns_, op_, parms_] :=
> Equal @@@ op[List @@@ eqns, parms]
>
> parallelmap2[eqns2, #1*#2 & , {c1, c2, c3}]
> parallelmap2[%, #1 - #2 & , {b1, b2, b3}]
> parallelmap2[%, #1/#2 & , {a1, a2, a3}]
> parallelmap2[%, Sqrt[#1] & , {d, d, d}]
>
> gives the same answers.
>
> David Park
> djmp at earthlink.net
> http://home.earthlink.net/~djmp/
>
>
[Hartmut Wolf]
Hello David,
I'd like to give you yet an alternative for parallelmap which, I think, is
clear and easy readable:
parallelmap3[eqns_, op_, parms_] :=
MapThread[Thread[op[##], Equal] &, {eqns, parms}]
Kind regards, Hartmut
Prev by Date:
**Re: Mathematica won't solve simple diff. eqn. system**
Next by Date:
**Re: Re: Re: More about l`Hopital`s rule**
Previous by thread:
**RE: A Functional Programming Question**
Next by thread:
**Re: A Functional Programming Question**
| |