Re: pure function to generate a list of integrals
- To: mathgroup at smc.vnet.net
- Subject: [mg77090] Re: pure function to generate a list of integrals
- From: Bill Rowe <readnewsciv at sbcglobal.net>
- Date: Sun, 3 Jun 2007 06:10:37 -0400 (EDT)
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