MathGroup Archive 2000

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

Search the Archive

RE: Hold, HoldForm, ReleaseHold when Plotting multiple functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg25487] RE: [mg25481] Hold, HoldForm, ReleaseHold when Plotting multiple functions
  • From: "David Park" <djmp at earthlink.net>
  • Date: Thu, 5 Oct 2000 23:50:09 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Sean,

This is really not a good example to learn about Hold's and ReleaseHolds.
You don't need them at all here and they only get in the way. Here is a
sample function which has two arguments as your bandwidth function has:

f[p_, x_] := Sin[x + p]

If you want to plot a series of curves for even values of p you can use:

Plot[Evaluate[Table[f[p, x], {p, 0.5, 1.9, 0.2}]], {x, 0, 12},
    PlotStyle -> Array[Hue[#/9.] &, 9]];

The Evaluate is important here because the arguments of Plot are
automatically held so the Table command must be explicitly evaluated. This
is discussed in Section 1.9.1 Basic Plotting, of the Mathematica Book.

If you want to Plot for some oddball set of values of p, you can use this
form.

Plot[Evaluate[f[#, x] & /@ {0, 0.3, 0.4, 0.7, 1.1}], {x, 0, 12},
    PlotStyle -> Array[Hue[#/9.] &, 9]];

I am not certain of a good plot example which illustrates the usefulness of
Holds, but here is a rather trivial one. Suppose we want a PlotLabel that
uses the f names and not the evaluated versions of f. We could then use:

Plot[Evaluate[f[#, x] & /@ {0, 0.3, 0.4, 0.7, 1.1}], {x, 0, 12},
    PlotStyle -> Array[Hue[#/9.] &, 9],
    PlotLabel ->
      SequenceForm[HoldForm[f[0, x]], " to ", HoldForm[f[1.1, x]]]];

HoldForm is often useful in teaching examples where you want to prevent
automatic evaluation of, say, integrals or derivatives. Here is an example
where HoldForm is used to represent an indefinite sum and even to do some
manipulation of its values.

HoldForm[{1, a, a^2, ?, a^(n - 1), a^n}]
% /. List -> Plus
% /. a -> 2*x

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

> -----Original Message-----
> From: Ross Sean Civ AFRL/DELO [mailto:Sean.Ross at kirtland.af.mil]
To: mathgroup at smc.vnet.net

>
> I wrote a function called bandwidth and want to print out a
> number of these
> functions on the same graph.  Here is an example:
> In[1]:=
>
> Plot[{bandwidth[28.5,x],
>   bandwidth[28.7,x],
>   bandwidth[28.9,x],
>   bandwidth[29.1,x],
>   bandwidth[29.3,x],
>   bandwidth[29.5,x],
>   bandwidth[29.7,x],
>   bandwidth[29.9,x]},{x,140,200},
>   PlotRange->{-5,5},PlotStyle->Array[Hue[#/9.]&,9]]
>
> Now, I personally think that listing out all those functions is a little
> clumsy.  I would rather put some kind of a Map statement as the
> argument to
> Plot.  Here is one that does the trick:
> In[2]:=
> Map[HoldForm[bandwidth[#,x]]&,{28.5,28.7,28.9,29.1,29.3,29.5,29.7,29.9}]
>
> However, using this code as the argument to Plot generates a lot of error
> messages and, ultimately, doesn't work.  I know that the solution has
> something to do with Hold, HoldForm, ReleaseHold, Evaluate etc.,
> but I have
> never been able to figure out what these things do or figure out which
> combination will work.
>
>
> I would greatly appreciate it if someone could tell me
>
> 1) what magic combination of Holds and Releases etc. would generate a
> multiple plot in the same time as the explicit version of In[1]
> and without
> generating error messages.  (Please don't refer me to other packages or
> other kinds of solutions or approaches like MultipleListPlot or Show.  I
> want to understand Holds and this is a good case in point.)
> 2) how I could have figured out what that magic combination was
> before hand
> by reading the Mathematica Book or something on the Wolfram web site.
>
> Please respond directly to Sean.Ross at kirtland.af.mil as I no longer
> subscribe to the mathgroup.
>
>
> Dr. Sean Ross
>
> AFRL/DELO
> 3550 Aberdeen Ave. Building 761
> Kirtland AFB, NM 87117
>



  • Prev by Date: Re:Mapping down two lists
  • Next by Date: Re: List element manipulation
  • Previous by thread: Re: Hold, HoldForm, ReleaseHold when Plotting multiple functions
  • Next by thread: RE: Hold, HoldForm, ReleaseHold when Plotting multiple functions