MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Controlling the order of evaluations

  • To: mathgroup at smc.vnet.net
  • Subject: [mg93039] Re: Controlling the order of evaluations
  • From: dh <dh at metrohm.ch>
  • Date: Fri, 24 Oct 2008 02:31:58 -0400 (EDT)
  • Organization: hispeed.ch
  • References: <gdms84$en$1@smc.vnet.net>


Hi Andres,

consider:

f[x_]:=If[NumericQ[x],1,Print["Not numeric"]];

Plot[f[x],{x,0,1}]

you will see that Plot first calls f with a non numerical argument. This 

is done to check if the evaluation of f can be speed up. To prevent 

this, you simply define f only for numerical arguments like:

Clear[f];

f[x_?NumericQ]:=If[NumericQ[x],1,Print["Not numeric"]];

Plot[f[x],{x,0,1}]

hope this helps, Daniel





anguzman at ing.uchile.cl wrote:

> Hello:

> Several times I have faced similar problems to this one:

> 

> Suppose I have a function f[x,y] well defined only in numbers, I mean, 

> it drops errors if I try to evaluate symbols. You could suppose that 

> is a function that include numerical integration in its definition...

> 

> What I want to do is plotting several curves f[x,y1], f[x,y2],...f[x,yn]

> with x as abscissa for specific (and fixed) values of y in the same plot.

> 

> So, what I always end up trying is something like:

> 

> 

> Plot[f[x,#]&/@{y1,y2,....,yn},{x,a,b}]

> 

> 

> Mathematica (5.2 Version for Windows) complains but finally interprets 

> correctly what I meant and does the plot correctly (sometimes)with all 

> the curves , but this errors are annoying. They are always of the form:

> 

> \" bla bla.. f[x,y1] is not numerical at ....\"

> 

> 

> 

> I would be very gratefull if somebody could explain me (or just give 

> the solution to this thing) the correct order of Holds, HoldFirsts, 

> HoldPatterns , Evaluate , Unevaluated etc... that make Mathematica 

> happy.

> By the way, I already tried:

> Plot[Evaluate[f[x,#]&/@{y1,y2,....,yn}],{x,a,b}]

> but didn=B4t work.

> 

> I=B4ll give an specific example:

> 

> f[x_, y_] := NIntegrate[2^(s*x), {s, 0, y}]

> 

> Plot[Evaluate[f[x, #] & /@ {2, 3, 4, 5}], {x, 0.5, 1.5}]

> 

> Generates the 4 curves after giving errors like:

> 

> \"NIntegrate::\"inum\" \"Integrand 2^(s*x) is not numerical at s = 1. \"

> 

> So what I want to do is that the x of the Plotting evaluation enters 

> f[x,y] before f even sees the x and start freaking out.

> 

> Thanks in advance

> 

> Atte. Andres Guzman

> 

> ----------------------------------------------------------------

> This message was sent using IMP, the Internet Messaging Program.

> 

> 





-- 



Daniel Huber

Metrohm Ltd.

Oberdorfstr. 68

CH-9100 Herisau

Tel. +41 71 353 8585, Fax +41 71 353 8907

E-Mail:<mailto:dh at metrohm.com>

Internet:<http://www.metrohm.com>




  • Prev by Date: RE: Re: Executing an external notebook within another notebook
  • Next by Date: Re: Controlling the order of evaluations
  • Previous by thread: Re: Controlling the order of evaluations
  • Next by thread: Re: Controlling the order of evaluations