MathGroup Archive 1997

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

Search the Archive

Re: Errors While Creating Simple Graph

  • To: mathgroup at
  • Subject: [mg8356] Re: Errors While Creating Simple Graph
  • From: tburton at (Tom Burton)
  • Date: Tue, 26 Aug 1997 02:22:51 -0400
  • Organization: Brahea Consulting
  • Sender: owner-wri-mathgroup at

On 22 Aug 1997 02:49:16 -0400, in comp.soft-sys.math.mathematica you =

>When I ask Mathematica (2.2) to perform the following plot, it works as
>expected, drawing a plot of two intersecting lines:
>   Plot[{x + 1, 2x - 1}, {x, 0, 5}]
>   -Graphics-
>However, when I use substitution to provide the list of equations,
>something goes wrong, and the resulting graph is empty...

This is a genuine FAQ! The source of the symptom is the HoldAll attribute=
 of Plot. (Try Attributes[Plot].) This causes "%2" not to be evaluated as=
 the arguments of Plot are parsed. This parsing distinguishes between a =
single ordinate and a list of ordinates. Since "%2" does not have the =
form of a list, the overlay of Plot that is invoked processes only a =
single argument. Later, when %2 is expanded (repeatedly and redundantly =
for every abcissa!), the list is recovered, but too late.

The solution (see the Mathematica Book or online help) is to Evaluate the=
 function to be plotted:


Evaluate[] is recommended for most plots. So is Mathematica trying to =
make your life miserable with HoldAll? No, because pre-evaluation is not =
always possible, and when pre-evaluation is erroneously applied, the =
result can be the worst type of error: a wrong answer.  An earlier post =
of mine (or an attemped post--my ISP usually drops the ball on the way =
from UseNet to the mathgroup) discusses what can happen if you reverse =
the Hold* attribute or override it with Evaluate[] :--

-- begin earlier post (February 1997) --

When you override Hold*, you assert that the avalanche of transformations
resulting from pre-evaluation will stop short of anything that should =
until the local independent variable is set. Here are two examples where =
override fouls up:


Both graphs are straight lines without Hold* (or Unevaluated[]). The =
f pre-evaluates to 1 because the global variable x is set. The function =
pre-evaluates to THE NUMERICAL EVALUATION OF Random[] because it can: =
is manifestly independent of x. Yet what I want is repeated evaluation of

I know that these examples are trivial (and what good is a "plot" of =
but my experience with numerical analysis is that similar but less =
problems are common, so Hold is needed much of the time.

-- (end of earlier post) --

Tom Burton

  • Prev by Date: Re: Print[] and Mathematica 3.0
  • Next by Date: Re: Help with Mathematica Filenames
  • Previous by thread: Errors While Creating Simple Graph
  • Next by thread: Re: Errors While Creating Simple Graph