[Date Index]
[Thread Index]
[Author Index]
RE: Hold, HoldForm, ReleaseHold when Plotting multiple functions
*To*: mathgroup at smc.vnet.net
*Subject*: [mg25494] RE: [mg25481] Hold, HoldForm, ReleaseHold when Plotting multiple functions
*From*: Ross Sean Civ AFRL/DELO <Sean.Ross at kirtland.af.mil>
*Date*: Thu, 5 Oct 2000 23:50:14 -0400 (EDT)
*Sender*: owner-wri-mathgroup at wolfram.com
Thank you for your response, but I had already tried a plain, old Evaluate
and it is one of the forms that generates error messages, is slower than the
explicit form, but eventually works. This indicates that there is still
some subtle difference between
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]]
---and---
Plot[Evaluate[Map[bandwidth[#,x]&,{28.5,28.7,28.9,29.1,29.3,29.5,29.7,29.9}]
],{x,140,200},
PlotRange->{-5,5},PlotStyle->Array[Hue[#/9.]&,9]]
I had assumed that the difference between these forms had something to do
with Holds and order of execution, but you are telling me it does not. In
these kinds of problems, using a simple example, like a function Sin[p+x],
does not always reveal the same things that using a complicated function
involving root-finding does. If you have any further light to shed on this
problem, please let me know.
P.S.
I have several programming projects on indefinite hold due to cases where a
certain syntax works on simple functions but not complex ones with multiple
nested function calls. This is the big problem with many of the examples in
the documentation--they only work on simple, one line functions that don't
call other user-created functions.
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
Office: (505) 846-9148
Labs: (505) 853-6440/846-9289
Fax: (505) 853-0485
Email: sean.ross at kirtland.af.mil
-----Original Message-----
From: David Park [mailto:djmp at earthlink.net]
To: mathgroup at smc.vnet.net
Subject: [mg25494] RE: [mg25481] Hold, HoldForm, ReleaseHold when Plotting
multiple functions
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: Hold, HoldForm, ReleaseHold when Plotting multiple functions**
Next by Date:
**Re: Hold, HoldForm, ReleaseHold when Plotting multiple functions**
Previous by thread:
**RE: Hold, HoldForm, ReleaseHold when Plotting multiple functions**
Next by thread:
**Re: Hold, HoldForm, ReleaseHold when Plotting multiple functions**
| |