Re: Can't assign value to symbols
- To: mathgroup at smc.vnet.net
- Subject: [mg58450] Re: Can't assign value to symbols
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Sat, 2 Jul 2005 04:07:15 -0400 (EDT)
- Organization: The Open University, Milton Keynes, England
- References: <da2mpq$93f$1@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Lee Newman wrote: > Hello, > > Situation: I have a table that contains parameters and sets of values > that I want to assign to the parameters for the purposes of running a > simulation. > - parameters = {{a,b,c},{1,2,3},{4,5,6},{7,8,9}} > - want to assign values in a given row to the symbols listed in the > first row. > - tried using: MapThread[ #1 = #2 &, {parameters[[1]], parameters[[3]]} ] > - fails with error "Tag Slot in #1 is Protected" > - tried adding Unprotect[#1] and a variety of other attemps, but can't > get it to work. > > Anyone know how might accomplish this? > > Thanks, > Lee > > Hi Lee, You should use _Replacement Rules_ rather than assignments, as in the following examples: In[1]:= parameters = {{a, b, c}, {1, 2, 3}, {4, 5, 6}, {7, 8, 9}} Out[1]= {{a, b, c}, {1, 2, 3}, {4, 5, 6}, {7, 8, 9}} In[2]:= MapThread[#1 -> #2 & , {parameters[[1]], parameters[[3]]}] Out[2]= {a -> 4, b -> 5, c -> 6} In[3]:= a*x^2 + b*x + c /. % Out[3]= 6 + 5*x + 4*x^2 In[4]:= MapThread[#1 -> #2 & , {parameters[[1]], parameters[[4]]}] Out[4]= {a -> 7, b -> 8, c -> 9} In[5]:= Solve[a*x^2 + b*x + c == 0 /. %] Out[5]= {{x -> (1/7)*(-4 - I*Sqrt[47])}, {x -> (1/7)*(-4 + I*Sqrt[47])}} Best regards, /J.M.