Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2000
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

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: [mg25513] 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:32 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Thank you for your reply, but as I said to David Park,  Evaluate[...]  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]]

(*This form works quickly and generates no error messages*)

		---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]]

(*This form works more slowly, generates lots of error messages associated
with the functions called by bandwidth, especially the one that does root
finding, but eventually plots the desired functions*)

Using simple examples for the two-argument function, bandwidth, does not
reveal the same issues that a complicated function does.  There are many
cases in which syntax that works for simple, one-line algebraic functions
does not work the same way for complex functions that call other
user-created functions or involve non-algebraic computations like numerical
differentiation or root finding.  If you have any further light to shed on
this subject, please respond to sean.ross at kirtland.af.mil.



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: Matt.Johnson at autolivasp.com [mailto:Matt.Johnson at autolivasp.com]
To: mathgroup at smc.vnet.net
Subject: [mg25513] Re: [mg25481] Hold, HoldForm, ReleaseHold when Plotting
multiple functions



Sean-

No Holds etc are necessary.  When you Map the function over the values, a
list of equations in y alone are returned.  You must simply evaluate these
inside Plot to get the graphics.

In[15]:=
\!\(\(f[x_, y_] := x\^2 + x\ y + y\^2;\)\n
  funs = Map[f[#, y] &, {2, 3, 4, 5}]\)
Out[16]=
\!\({4 + 2\ y + y\^2, 9 + 3\ y + y\^2, 16 + 4\ y + y\^2, 25 + 5\ y + y\^2}\)

Plot[Evaluate[funs], {y, -10, 10}];

produces the desired type of plot.

-matt





Ross Sean Civ AFRL/DELO <Sean.Ross at kirtland.af.mil> on 10/02/2000 08:26:59
PM

cc:

Subject: [mg25513]  [mg25481] Hold, HoldForm, ReleaseHold when Plotting multiple
      functions


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.

Here are some combinations I have tried that kind of work:
In[3]:=
Plot[Evaluate[ReleaseHold[Map[HoldForm[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]]
In[4]:=
Plot[Evaluate[ReleaseHold[Map[Hold[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]]

In[3] and In[4] generate lots of error messages and take a long time, but
print out the multiple graph.  I have tried other combinations that don't
work at all.

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

Office:    (505) 846-9148
Labs:      (505) 853-6440/846-9289
Fax:        (505) 853-0485
Email:     sean.ross at kirtland.af.mil








  • Prev by Date: Re: Bug: Mathematica multipies statements together
  • 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