Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

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

Search the Archive

Re: local symbols inside Module

  • To: mathgroup at smc.vnet.net
  • Subject: [mg56029] Re: [mg55950] local symbols inside Module
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Thu, 14 Apr 2005 08:54:20 -0400 (EDT)
  • References: <200504120926.FAA27549@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 12 Apr 2005, at 18:26, OT wrote:

> Hi all, I have some problems in working with local variables inside
> Module: I wrote this function:
>
> RealLinearCombination[v_List]:=Module[{d,coeffs},
> d=Legth[v];
>
> coeff=Table[ToExpression["c"<>ToString[k]],{k,d}];
>
> coeffs=coeffs/.Solve[eqns,coeffs];
>
> ...
> ...
>
> ]
>
> The function works, but has a big limitation: the elements of the list
> coeffs are not local symbols!
>
> Since the elements of the list coeffs are not local variables, if I run
> my function when I have already initialized a symbol like c3=Pi, say, I
> get an error because mathematica tries to execute
> Solve[eqns,{c1,c2,Pi,c4,...,cd}] since c3 has been already initialized
> as a number.
>
> So, my question is: how can I initialize a local list of symbols
> {c1,...cd} inside a Module, when d is an argument supplied to the 
> Module
> itself?
>
> Thanks for every answer!
>
>
>

Since obviously you do not need your local variables to be named in c1, 
c2 etc, you might as well simply use:

RealLinearCombination[v_List]:=Module[{d,coeffs,c},
d=Legth[v];

coeffs = Map[Unique, Table[c, {d}]]];

coeffs=coeffs/.Solve[eqns,coeffs];

...
...

]




Andrzej Kozlowski
Chiba, Japan
http://www.akikoz.net/andrzej/index.html
http://www.mimuw.edu.pl/~akoz/


  • Prev by Date: Re: Infinite sum of gaussians
  • Next by Date: Re: Infinite sum of gaussians
  • Previous by thread: local symbols inside Module
  • Next by thread: Re: local symbols inside Module