Re: Controlling the order of evaluations

*To*: mathgroup at smc.vnet.net*Subject*: [mg93038] Re: Controlling the order of evaluations*From*: Bill Rowe <readnews at sbcglobal.net>*Date*: Fri, 24 Oct 2008 02:31:46 -0400 (EDT)

On 10/22/08 at 5:37 AM, anguzman at ing.uchile.cl wrote: >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. There are two issues here. First, you need to define your function to operate on numeric values rather than more general values. Second, you need to Evaluate the list of things you give Plot as an argument so that Plot sees it as things it can substitute numeric values for the independent variable and evaluate. >I will give an specific example: >f[x_, y_] := NIntegrate[2^(s*x), {s, 0, y}] re-write this as f[x_?NumericQ, y_NumericQ] := NIntegrate[2^(s*x), {s, 0, y}] the the following will work; >Plot[Evaluate[f[x, #] & /@ {2, 3, 4, 5}], {x, 0.5, 1.5}] But note this is rather slow because you are re-computing numerically the integral every time Plot supplies a new value for x. Much faster is: f = Integrate[2^(s*x), {s, 0, y}]; Plot[Evaluate@Table[f, {y, 2, 5}], {x, 0.5, 1.5}]

**Re: Controlling the order of evaluations**

**Re: Controlling the order of evaluations**

**Re: Controlling the order of evaluations**

**Re: Controlling the order of evaluations**