MathGroup Archive 1999

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

Search the Archive

Re: Working in Modules

  • To: mathgroup at
  • Subject: [mg15913] Re: [mg15860] Working in Modules
  • From: Andrzej Kozlowski <andrzej at>
  • Date: Wed, 17 Feb 1999 23:33:51 -0500
  • Sender: owner-wri-mathgroup at

On Fri, Feb 12, 1999, Dr D McK Paul <phrje at> wrote:

>This is my third attempt to post this question. No idea why it doesnt
>work. I'm not an expert in Mathematica and would appreciate comments on
>why init1 returns a list with all zeros replaced by -1, but init does
>not. Its probably very simple but its confused me.
>                    {s=Table[Random[Integer],{n n}]},
>                    s/.{0->-1};
>                    Partition[s,n]
>                    ]
>                    {s=Table[Random[Integer],{n n}]},
>                    s/.{0->-1}
>                    ]
>Prof. Don McKenzie Paul               tel.  (1203) 523603 Department of
>Physics                 fax.  (1203) 692016 University of Warwick      
>email  phrje at COVENTRY CV4 7AL
>****************************************************** Professor Don
>McKenzie Paul
>Department of Physics
>University of Warwick

Yes, it is indeed very simple and at the same time confusing. All you
need to do with your init function is to replace it by the following code:

                    {s=Table[Random[Integer],{n n}]},

You see, your original code for init  does not change the value of s at
all! It computes s/.{0->-1} but does nothing with it! On the other hand
init1 also does not change the value of s, but it does return s/.{0->-1}
which is of course what you wanted.

Andrzej Kozlowski
Toyama International University

Andrzej Kozlowski
Toyama International University

  • Prev by Date: RE: Dont Understand
  • Next by Date: Mathematica Training (UK and US)
  • Previous by thread: Working in Modules
  • Next by thread: Re: Working in Modules