Re: Equality...

*To*: mathgroup at smc.vnet.net*Subject*: [mg125716] Re: Equality...*From*: A Retey <awnl at gmx-topmail.de>*Date*: Fri, 30 Mar 2012 04:30:47 -0500 (EST)*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com*References*: <jl14hh$l4t$1@smc.vnet.net>

Hi, > > I have a matrix with nxn varaibles an entry and want to assign values > to each of the entries. How can I do this in one go? > > I was hoping something like this works, but it doesn't... > > Array[Subscript[a, #1, #2]&, {3, 4}] = Array[Random[1], {3, 4}] > > Any tips are apprecited. Set has attribute HoldFirst (for obvious reasons). It does partially evaluate its first argument in some cases, but not in this. So you need an explicit Evaluate (note that this will only work if no corresponding values were defined before): Evaluate[Array[Subscript[a, #1, #2] &, {3, 4}]] = RandomReal[{0, 1}, {3, 4}] It's not trivial to unset those definitions which you need to do if you want to reset those values, here is something I came up with, but I feel there must be simpler methods: ReleaseHold[ Map[Unset, Block[{Subscript}, Hold @@ {Array[Subscript[a, #1, #2] &, {3, 4}]}], {3}] ] On the other hand, I would suggest to use either: a = RandomReal[{0, 1}, {3, 4}] and then access these values with: a[[i,j]] or (note that this is one of the cases where the first argument of Set is partially evaluated): Do[a[i,j]=RandomReal[],{i,3},{j,4}] and: a[2,3] which will make your life easier when actually working with these in the following code. hth, albert