Re: local symbols inside Module

*To*: mathgroup at smc.vnet.net*Subject*: [mg55981] Re: local symbols inside Module*From*: dh <dh at metrohm.ch>*Date*: Wed, 13 Apr 2005 01:10:05 -0400 (EDT)*References*: <d3g81p$s8r$1@smc.vnet.net>*Sender*: owner-wri-mathgroup at wolfram.com

Hi OT, Instead of using symbols you can as well use function values. E.g. for storing Pi: instead c1=Pi you may use c[1]=Pi. Your example, with the local function name "c", would then look like: RealLinearCombination[v_List] := Module[{d, coeffs, c}, d = Length[v]; coeffs = Array[c, {d}]; coeffs = coeffs /. Solve[eqns, coeffs]; .. ] Sincerely, Daniel 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! >