RE: Hold, HoldForm, ReleaseHold when Plotting multiple functions

*To*: mathgroup at smc.vnet.net*Subject*: [mg25499] 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:19 -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]] ---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 y/x - 5, does not always reveal the same things that using a complicated function that involves root-finding and calls several other user-defined functions does. If you have any further light to shed on this problem, please let me know. I could send you the notebook so you can look at the code yourself. I have several projects on indefinite hold because the syntax that works for simple functions does not work for complicated functions, so understanding the subtleties involved would be of great assistance. If you have time to look over the code, let me know and I will send it to you. Please respond to sean.ross at kirtland.af.mil as I do not 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: Daniel Lichtblau [mailto:danl at wolfram.com] To: mathgroup at smc.vnet.net Subject: [mg25499] Re: [mg25481] Hold, HoldForm, ReleaseHold when Plotting multiple functions Ross Sean Civ AFRL/DELO wrote: > > 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 A simple Evaluate suffices. For example, if I define In[33]:= bandwidth[x_,y_] := y/x - 5 Then the following all work fine. Plot[Evaluate[Table[bandwidth[j,x], {j,28.7,29.9,.2}]], {x,140,200}, PlotRange->{-5,5},PlotStyle->Array[Hue[#/9.]&,9]] 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]] Plot[Evaluate[Map[bandwidth[#,x]&, Range[28.5,29.9,.2]]], {x,140,200}, PlotRange->{-5,5},PlotStyle->Array[Hue[#/9.]&,9]] Daniel Lichtblau Wolfram Research