Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

Re: specifying the integration interval using a function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg95811] Re: [mg95794] specifying the integration interval using a function
  • From: "David Park" <djmpark at comcast.net>
  • Date: Wed, 28 Jan 2009 06:27:41 -0500 (EST)
  • References: <14572644.1233060109419.JavaMail.root@m02>

NIntegrate has the Attribute HoldAll. So maybe you can try applying Evaluate
to the integration interval. You could also use Sequence to insert the
s[x,D] arguments.

s[x, D] = {x - D, s1, s2, s3, x + D};
NIntegrate[f[y], Evaluate@Flatten@{y, s[x, D]}]

s[x, D] = {x - D, s1, s2, s3, x + D};
NIntegrate[f[y], Evaluate@{y, Sequence @@ s[x, D]}]


David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/  



From: pfb [mailto:pf.buonsante at gmail.com] 


Hi everybody,

 is it possible to specify the integration interval using a function?
My problem is as follows:

I have some function f[x] I want to integrate. Actually I want to
obtain a sort of running average, i.e. a
function F[x,D] given by the integral of f[x] over the interval [x-D, x
+D].
So far, it's easy. I can do that with the following function

F[x_,D_]:= NIntegrate[f[y],{y,x-D,x+D}]

However, the function f may have some (integrable) singularities in
the integration interval.
I know that NIntegrate finds it helpful if one tells it the locations
of the singularities.
So I thought: easy! I just need a function s[x,D] whose output is  {x-
D, s1,s2,s3, x+D}.,
where s1, s2, .. are the singularities of f in the interval.

I have such a function, but I'm not able to feed it into NIntegrate.
I have tried

F[x_,D_]:= NIntegrate[f[y],Flatten[{y,s[x,D]}]]

but mathematica complains that Flatten[{y,s[x,D]}] is not a correct
integration range specification, despite
its evaluation (in a separate cell) gives what I'd expect, i.e. {y,x-
D,s1,s2,s3,x+D}.

I also tried something like

r[y_,x_,D_]:=Flatten[{y,s[x,D]}]

which again gives {y,x-D,s1,s2,s3,x+D}, and then tried


F[x_,D_]:= NIntegrate[f[y],r[y,x,D]]

Mathematica complains also in this case: r[y,x,D] is not a correct
integration range specification.

In both case it seems that the function providing the integration
range is not evaluated.
Has this anything to do with delayed set (:=)?

Is there another way of dealing with the intermediate points in an
integration interval?

Thanks a lot

F





  • Prev by Date: Re: Problem with spline function object in Mathematica 6
  • Next by Date: domains as sets
  • Previous by thread: Re: specifying the integration interval using a function
  • Next by thread: Re: Clever Tricky Solutions