MathGroup Archive 2003

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

Search the Archive

Re: HoldForm Question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg41358] Re: HoldForm Question
  • From: Torben Winther Graversen <immtwg at remove.student.dtu.dk>
  • Date: Fri, 16 May 2003 06:40:45 -0400 (EDT)
  • Organization: UNI-C
  • References: <b9viur$e0i$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Dana DeLouis <delouis at bellsouth.net> wrote:
[...]
: In this simple table, I would like to first substitute the values of r &
: c, but then not reduce the equation.

: MatrixForm[Table[HoldForm[(2*Pi*r*c)/8], {r, 0, 7}, {c, 0, 7}]]

: I would like "2 Pi 0 0 / 8",  "2 Pi 0 1 / 8"....etc

Hi Dana,

When Table evaluates it's expression it does it by
temporarily assigning each value to the loop variables.
Sort of like:

In[1]:= r = 0; c = 0;
In[2]:= HoldForm[(2*Pi*r*c)/8]
In[3]:= r = 0; c = 1;
In[4]:= HoldForm[(2*Pi*r*c)/8]

...which does not replace the value of r and c, since they
are held by HoldForm. Look in the book about Block[] for
more on that. What you want is Replace or just "/.":

Table[HoldForm[(2*Pi*r*c)/8] /. {r->r1, c->c1}, 
      {r1, 0, 7}, {c1, 0, 7}]

This will perform the replacement for each value. Replace
doesn't mind that the expression is held. Actually, you 
don't need the extra variables r1 and c1 as long as you
use HoldPattern:

Table[ HoldForm[(2*Pi*r*c)/8] /. 
         {HoldPattern[r]->r, HoldPattern[c]->c},
       {r, 0, 7}, {c, 0, 7}]

See section A.4.4 for a short list of the use of the different
Hold's. (http://documents.wolfram.com/v4/MainBook/A.4.4.html)

Hope that helps.

- Torben


  • Prev by Date: Re: Show and GraphicsArray and DisplayFunction
  • Next by Date: Re: Scientific notation
  • Previous by thread: Re: HoldForm Question
  • Next by thread: Re: HoldForm Question