MathGroup Archive 2002

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

Search the Archive

Re: Generate expression from result

  • To: mathgroup at smc.vnet.net
  • Subject: [mg32861] Re: Generate expression from result
  • From: "Allan Hayes" <hay at haystack.demon.co.uk>
  • Date: Sat, 16 Feb 2002 04:35:17 -0500 (EST)
  • References: <a4aum0$bug$1@smc.vnet.net> <a4fnvu$j4j$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Johanes, Albert,
An addition to Albert's posting.

Module only directly affects free variables.
In Johnes' example,

Module[{a1, a2, f}, f[{a1_, a2_}] = LinearSolve[m[{a1, a2}], b[{a1, a2}]]]

a1 in a1_  is bound to the  a1's  in m[{a1, a2}], b[{a1, a2}], similarly for
a2.

However there can be indirect effects on bound variables because of of the
need to preserve their formal nature:

Module[{b},f[a_]:={a,b};
  Print[DownValues[f]]
  ]

{HoldPattern[f[a$_]]:>{a$,b$31}}

Here, Module changed b and this provoked a change in the a's.

--
Allan

---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565


"Albert Retey" <albert.retey at visualanalysis.com> wrote in message
news:a4fnvu$j4j$1 at smc.vnet.net...
> Johannes Ludsteck wrote:
> >
> > Dear Mathgroup Members,
> > I obtain the vector {x1,x2} as solution to a
> > (rather complicated) equation system
> >
> > {x1,x2}=LinearSolve[m[{a1,a2}],b[{a1,a2}]]
> > Of course, the xi are functions of {a1,a2}.
> >
> > Since I use the xi later on for complex operations,
> > it would be of gread help if the arguments ai appeared
> > in the vector {x1,x2}.
> > Therefore I defined
> > f[{a1_,a2_}]=LinearSolve[m[{a1,a2}],b[{a1,a2}]]
> >
> > (I need "=" here instead of ":=", since f[] is called
> > often and the LinearSolve[] command uses some time,
> > since the vectors {x1,x2} and {a1,a2} are only
> > examples and can have dimension 10 to 20 in my application.
> >
> > Up to now the solution works well, but I am bothering
> > whether this construction could generate modularity or
> > naming problems, since the Assignment
> > appears in a Module where {a1,a2} are defined as local variables.
> >
> > fun[...]:=Module[{a1,a2,f},
> >         ...
> >         f[{a1_,a2_}]=LinearSolve[m[{a1,a2}],b[{a1,a2}]]
> >         ...
> > ]
> >
> I think they are save, as you can see when evaluating the following.
>
> Module[{a1, a2, f}, f[{a1_, a2_}] = LinearSolve[m[{a1, a2}], b[{a1,
> a2}]];
>   Print[DownValues[f]];
>   Print[a1];
>   Print[a2];
>   ]
>
> If things get more complicated I don't know, but why not just use
> different names for the f-pattern to be on the save side?
>
> HTH
>
> Albert
>




  • Prev by Date: Re: A Learning TableForm Problem
  • Next by Date: Re: RSolve
  • Previous by thread: Re: Generate expression from result
  • Next by thread: Fourier and differential function