MathGroup Archive 2007

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

Search the Archive

Re: numeric integration


found two simple solutions:

1) writing

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

instead of

f = NIntegrate[Sin[x + #], {x, 0, 1}] &

2) writing

NIntegrateF[f, {0, 0.1}]

instead of

NIntegrate[f[x], {x, 0, 0.1}]

with the definition

NIntegrateF[f_ , a_] :=
Module[{F},
F[x_?NumericQ] = f[x];
NIntegrate[F[x], {x, a[[1]], a[[2]]}]
];

c. seja


> Hi,
>
> 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. 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)?
>
> Regards
>
> C. Seja
>
>
> 




  • Prev by Date: Changing Textbook.nb to label equations (chapter.section.equation)
  • Next by Date: Re: How to make delayed functions from text info
  • Previous by thread: Re: numeric integration
  • Next by thread: Re: Re: numeric integration