MathGroup Archive 2009

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

Search the Archive

pure function with an NIntegrate command


Hi,

I posted a question yesterday about pure functions. Probably when you 
receive this message someone would have
posted a solution. While I was waiting I managed to come closer to a 
possible solution, and the encountered another
problem.

This is my problem. I define a function

Efun[x_, y_, z_] := x + y + z

and then this other one, which does an integral using the previous function

fintnp[list_, y_, z_] :=NIntegrate[Efun[x, y, z], {x, 0, #}] & /@ list

In my computer I run

fintnp[{1, 2, 3, 4}, 0.2, 0.3] // Timing

and get {0.020001, {1., 3., 6., 10.}}

Now I want to construct a pure version of fintnp so that when the list 
is long I save a good load of time.

My first approach is

fint = Integrate[Efun[x, ##2], {x, 0, #1}] &

It gives the correct results but it is significantly slower because I 
use Integrate instead of NIntegrate, so I naively define

fintn= NIntegrate[Efun[x, ##2], {x, 0, #1}] &

and then get errors indicating the definition is not good. Can someone 
help me?

Thanks is advance.

Ruth

PD: Mathgroup is awesome, it has been amazingly useful for my work, and 
all the things I learn here made me a stronger Mathematica advocate anyday.


  • Prev by Date: Re: Re: Mathematica for gifted elementary school children
  • Next by Date: Re: Help with Speeding up a For loop
  • Previous by thread: Re: Alignment of Graphics Within Expressions
  • Next by thread: Re: Alignment of Graphics Within Expressions