Re: ContourPlot, etc.: not every point a Real

*To*: mathgroup at smc.vnet.net*Subject*: [mg87506] Re: ContourPlot, etc.: not every point a Real*From*: dh <dh at metrohm.ch>*Date*: Fri, 11 Apr 2008 05:59:30 -0400 (EDT)*References*: <ftmtr7$4k2$1@smc.vnet.net>

Hi Will, ContourPlot first calls Eval with symbolic arguments in order to check if it can simplify the expression. This is done to improve speed. You can suppress this, by specifying that the arguments must be numeric, e.g.: Eval[x__?NumericQ] take care to clear first the old definitions of Eval. hope this helps, Daniel Will Robertson wrote: > Hello, > > I just discovered something a little strange and hoped someone here > might be able to shed some light on the matter. (I'm using Mathematica 6.0.1.) > > Take this following code. It defines a function and uses it in a > contour plot; the trick is that every value is intercepted on the way > through (I use this in ColorbarPlot to extract max/min values): > > fn := #1^3 + #2^2 & > everyNonReal = {}; > Eval[x__] := Module[{val = Evaluate@fn@x}, > If[Head@val =!= Real, AppendTo[everyNonReal, val]]; val] > ContourPlot[Eval[x, y], {x, -2, 2}, {y, -2, 2}] > Union@everyNonReal > > If every evaluation of fn resulted in a Real (as I would expect), then > the output should be {} as the if statement would never evaluate. But > there's a point in there that's *not* being evaluated, as you can see. > > What's going on? Working around this problem results in an extra If > statement for every single evaluated point, a state of affairs I'm not > so fond of. > > Many thanks, > Will >