Re: Re: pure function to generate a list of integrals]

• To: mathgroup at smc.vnet.net
• Subject: [mg77192] Re: [mg77090] Re: pure function to generate a list of integrals]
• From: Ruth <ruth.lazkoz at ehu.es>
• Date: Tue, 5 Jun 2007 06:51:25 -0400 (EDT)

```Thanks to everyone. Bill's was the purest solution of them all (if I
understand correctly the meaning of purity). However, my example was to
naive (linear).

I would like to have a new function with basically the same purity as
Bill's solution

f = #1 Block[{x}, NIntegrate[x, {x, 0, #}] & /@ #2] &;

but this time to be able to produce the equivalent of

{NIntegrate[Sqrt[2x+3], {x, 0, 0.1}], NIntegrate[Sqrt[2x+3], {x, 0, 0.5}],
NIntegrate[Sqrt[2x+3], {x, 0, 0.9}]}

when evaluating f[2,3,{0.1,0.5,0.9}]

Thanks again.

Bill Rowe escribió:
> On 6/2/07 at 4:17 AM, ruth.lazkoz at ehu.es (Ruth Lazkoz Saez) wrote:
>
>
>> I am trying to brush up a long code I have to make it more compliant
>> with the spirit of functional programming. I do not like to hear
>> that the kind of calculations I do should run faster in C, because I
>> suspect that if I managed to write good code in Mathematica it
>> should be as fast. So I have to go and improve my code chunk by
>> chunk.
>>
>
>
>> My first problem is that I want to generate a pure function say f,
>> which, so that f[2, {0.1, 0.5, 0.9}] gives me the same output as
>>
>
>
>> {NIntegrate[2x, {x, 0, 0.1}], NIntegrate[2x, {x, 0, 0.5}],
>> NIntegrate[2x, {x, 0, 0.9}]}
>>
>
> This will do the trick
>
> f = #1 Block[{x}, NIntegrate[x, {x, 0, #}] & /@ #2] &;
>
> Checking:
>
> In[14]:= f[2, {0.1, 0.5, 0.9}]
>
> Out[14]= {0.01,0.25,0.81}
>
> In[15]:= f[3, {0.1, 0.5, 0.9}]
>
> Out[15]= {0.015,0.375,1.215}
> --
> To reply via email subtract one hundred and four
>
>
>

```

• Prev by Date: Re: Very Strange Behaviour about something Very Simple
• Next by Date: Re: Unable to copy graphics from Mathematica 6 to Publicon
• Previous by thread: Re: v6: weird cursor behaviour
• Next by thread: Dynamic 2D plotting in V6