MathGroup Archive 2002

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

Search the Archive

RE: Setting up dummy variables

  • To: mathgroup at smc.vnet.net
  • Subject: [mg35839] RE: [mg35813] Setting up dummy variables
  • From: "David Park" <djmp at earthlink.net>
  • Date: Sat, 3 Aug 2002 00:16:24 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Christopher,

i = 6;

If you set up the definition...

f[i_] = i^2
36

...Mathematica immediately evaluates the right hand side and i has a value
of 6. I am not certain why the designers choose to ignore that i_ is a
pattern variable on the lhs. So if you subsequently evaluate f[x] you obtain
36. Not what must people want! This is a regular source of confusion.

The method that works is to use a delayed set (:= instead of =).

Clear[f]
f[i_] := i^2

Then

f[x]
x^2

But since i still has a value

f[i]
36

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/




From: Christopher Maierle [mailto:chris at chaos.Physik.uni-dortmund.de]
To: mathgroup at smc.vnet.net

Hi all,

How do I set up a function that behaves like the Mathematica function Sum
vis-a-vis
its treatment of dummy variables?  For example I can define i=6 and then
enter

Sum[f[i],{i,1,n}]

and mathematica will not make the substitution i->6 even though the output
generally still involves the dummy variable i.  I figure this has something
to do with Modules, Blocks, and Holds but I'm not sure how to put it all
together.  Any help would be greatly appreciated.

-chris



  • Prev by Date: Re: Flickering Graphics
  • Next by Date: RE: Re: aligning equations
  • Previous by thread: Setting up dummy variables
  • Next by thread: Re: Setting up dummy variables