MathGroup Archive 2007

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

Search the Archive

Re: numeric integration


C. Seja wrote:

> I'd like to intergate a function f with NIntegrate:
> NIntegrate[f[x], {x, 0, 0.1}]
> 
> But this doesn't work if, i.e.
> 
> f = NIntegrate[Sin[x + #], {x, 0, 1}] &
> 
> It will give a wrong result (0.7 instead of 0.05). Why? I mean, I can 
> evaluate f at any point without problems, i.e. f[0.1] gives 0.37. 

In[1]:= f = NIntegrate[Sin[x + #], {x, 0, 1}] &;
f[0.1]

Out[2]= 0.541408

> So why doesn't
> 
> NIntegrate[f[x], {x, 0, 0.1}]
> 
> work? It doesn't even give a warning! So, is there a proper way to do this 
> (without using one two-dimensional NIntegrate)?

In[1]:= f[y_?NumericQ] := NIntegrate[Sin[x + y], {x, 0, 1}]

In[2]:= f[0.1]

Out[2]= 0.541408

In[3]:= NIntegrate[f[y], {y, 0, 0.1}]

Out[3]= 0.050097

Regards,
-- 
Jean-Marc


  • Prev by Date: Re: Optimization with symbolic paramters
  • Next by Date: HELP!
  • Previous by thread: Re: numeric integration
  • Next by thread: Re: numeric integration