Re: Confusing Behavior of LogPlot vs. Plot
- To: mathgroup at smc.vnet.net
- Subject: [mg24843] Re: Confusing Behavior of LogPlot vs. Plot
- From: "Allan Hayes" <hay at haystack.demon.co.uk>
- Date: Wed, 16 Aug 2000 03:24:08 -0400 (EDT)
- References: <8naqgs$f02@smc.vnet.net>
- Sender: owner-wri-mathgroup at wolfram.com
Tony, I give an explanation and a work-round. Needs["Graphics`"]; f[a_, x_] := Exp[-a x^2]; x = 3.; a = 4; LogPlot[f[a, x], {x, -1, 1}] // Short ScaledPlot[{f[a, x]}, <<4>>, Options[Li<<10>>t]] Explanatiin: Attributes[LogPlot] {HoldFirst} So the x in in { x, -1, 1} is picking up the assignment x=3 and we are then evaluating LogPlot[f[a, x], {3., -1, 1}]. (why is LogPlot not protected?) This evaluation of x does not happen with Plot because Attributes[Plot] {HoldAll, Protected} Work-round: We can block out x and get the graphics: Block[{x}, a = 4; LogPlot[f[a, x], {x, -1, 1}]]; but, unfortunately, simply giving LogPlot the attribute HoldAll does not work - the package needs to be be examined. -- Allan --------------------- Allan Hayes Mathematica Training and Consulting Leicester UK www.haystack.demon.co.uk hay at haystack.demon.co.uk Voice: +44 (0)116 271 4198 Fax: +44 (0)870 164 0565 "AES" <siegman at stanford.edu> wrote in message news:8naqgs$f02 at smc.vnet.net... > If I run the following input cells with the "Table" cell commented out > as shown, I get four valid and correct plots. > > Remove["Global`*"] > > Needs["Graphics`"] > > f[a_, x_] := Exp[-a x^2] > > a = 1; Plot[f[a, x], {x, -1, 1}] > > a = 1; LogPlot[f[a, x], {x, -1, 1}]; > > (* x = 3.; Table[{a, f[x, a]}, {a, 0, 2}] // TableForm *) > > a = 4; Plot[f[a, x], {x, -1, 1}] > > a = 4; LogPlot[f[a, x], {x, -1, 1}] > > If, however, I remove the (* and *) and run the notebook including the > "Table" input cell, both "Plot" plots are still fine, still give correct > results, but the second "LogPlot" cell doesn't give me a plot at all, it > gives me the list of options for something called "ScaledPlot". > > (With various other test circumstances, the repeated "Plot" cells always > continue to function OK, but the repeated "LogPlot" cell gives other > weird results, e.g, a totally incorrect plot.) > > If I've somehow goofed on this, I apologize -- but if this is how > LogPlot really works, I'd say that's inexcusably bad interface design. > If LogPlot looks, smells, and feels like Plot, and does essentially the > same job as Plot, it should *function* just like Plot. >