MathGroup Archive 2012

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

Search the Archive

Re: Equality...

  • To: mathgroup at
  • Subject: [mg125716] Re: Equality...
  • From: A Retey <awnl at>
  • Date: Fri, 30 Mar 2012 04:30:47 -0500 (EST)
  • Delivered-to:
  • References: <jl14hh$l4t$>


> 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:

    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:


or (note that this is one of the cases where the first argument of Set 
is partially evaluated):




which will make your life easier when actually working with these in the 
following code.



  • Prev by Date: Re: Schaums outline Mathematica 2nd ed, prob. 11.3 help
  • Next by Date: Re: PC auto-simplifies output, but mac doesn't
  • Previous by thread: Re: Equality...
  • Next by thread: PC auto-simplifies output, but mac doesn't