Re: Re: Hold, HoldForm, ReleaseHold when Plotting multiple functions
- To: mathgroup at smc.vnet.net
- Subject: [mg25562] Re: [mg25514] Re: [mg25481] Hold, HoldForm, ReleaseHold when Plotting multiple functions
- From: "Benjamin A. Jacobson" <bjacobson at illumitech.com>
- Date: Sat, 7 Oct 2000 03:36:09 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
OK, after correcting several typos, I was able to solve part of the problem. Plot[Evaluate[Map[bandwidth[#,x][[1]]&,{28.5,28.7,28.9,29.1,29.3,29.5,29 .7,29.9}]],{x,140,200} tries to evaluate, for example, bandwidth[28.5,x]. Sean's bandwidth function eventually evaluates something like FindRoot[f[28.5,x]==0]. Since x is a symbol, FindRoot spits back a bunch of error messages. You can avoid the error messages in two ways: 1) 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}] does the job; or 2) Make sure that f, the function that includes FindRoot, doesn't evaluate with symbolic arguments, by modifying the definition to f[var1_?NumericQ,var2_?NumericQ, etc.]. I prefer the 2nd way because the logic is clearer and because it has applications besides Plot, Table, etc. I find that, in general, whenever I have a function that calls any numerical routine like FindRoot or NDSolve, I can avoid problems by using _?NumericQ in the calling function. In Sean's case, both these methods got rid of the error messages. However, they still don't produce the exact same plots as Plot[{bandwidth[28.5, x][[1]], bandwidth[28.7, x][[1]], bandwidth[28.9, x][[1]], bandwidth[29.1, x][[1]], bandwidth[29.3, x][[1]], bandwidth[29.5, x][[1]], bandwidth[29.7, x][[1]], bandwidth[29.9, x][[1]]},{x,140,200}] I can't see why the numerical results should be different, but I'll leave that to others. Ben Jacobson Illumitech Inc. http://www.illumitech.com At 11:50 PM 10/5/00 -0400, you wrote: > >Ok, I have attached the notebook showing an example of when >Plot[Evaluate[...]..] does not work the same as explicitly listing each >function you want to plot. The error messages all come from FindRoot, one >of the functions called by the functions I am trying to Plot. One of the >resondents to my message said that the only thing he could think of was >"some weird interaction with another HoldAll function, like FindRoot". That >is exactly the case and this "weird interaction" has stalled several >programming projects for me. In one particular case using functions far >more nested than the ones in this notebook, the result is that a certain set >of functions gives different results when called within another function >compared to what they give when called directly, so this "weird interaction" >is a matter of some concern to me and has plagued me for a couple of years >now. If anyone has any light to shed on the matter, please respond to: >Sean.Ross at kirtland.af.mil > > <<FPOPO_tuningcurves.mathgroup.nb>> >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