Message Boards Message Boards

0
|
13904 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

Numerical integration of a function defined by numerical integration

Posted 11 years ago
Hi,
Sometimes one will define functions that are defined by numerical integration and then perhaps use such functions in another numerical integration. In Mathematica 4.0 this works fine, but in 9.0 this results in error messages and the execution is much slower than in 4.0. Here is an example:
F[a_, b_, c_] := Sin[a + b + c]
H[a_, b_] := NIntegrate[F[a, b, c], {c, 0, 1}]
G[a_] := NIntegrate[H[a, b], {b, 0, 2}]

Then the evaluation of G[1] gives several warnings:
NIntegrate::inumr: The integrand Sin[1+b+c] has evaluated to non-numerical values for all sampling points in the region with boundaries {{0,1}}. >>
NIntegrate::inumr: The integrand Sin[1+b+c] has evaluated to non-numerical values for all sampling points in the region with boundaries {{0,1}}. >>
NIntegrate::inumr: The integrand Sin[1+b+c] has evaluated to non-numerical values for all sampling points in the region with boundaries {{0,1}}. >>
General::stop: Further output of NIntegrate::inumr will be suppressed during this calculation. >>

and then the result
0.965749

How can I get rid of the warnings? There is obvious something that Mathematica 9 does not like in this construction.
POSTED BY: Olav Østerbø
3 Replies
Hello and welcome to the Wolfram Community! Please take a few minutes to read this tutorial about correct posting – especially of Mathematica code:

How to type up a post: editor tutorial & general tips

If you will not follow the tutorial, other members of community may not be able to test your code. To edit your post – click “Edit” in the lower right corner of your post.
POSTED BY: EDITORIAL BOARD
Posted 11 years ago
In[1]:= F[a_, b_, c_] := Sin[a + b + c];
H[a_], b_/;NumericQ[b]] := NIntegrate[F[a, b, c], {c, 0, 1}];
G[a_] := NIntegrate[H[a, b], {b, 0, 2}];
G[1]

Out[4]= 0.965749
POSTED BY: Bill Simpson
Alternatively, you can just evaluate
In[526]:= NIntegrate[F[1, b, c], {b, 0, 2}, {c, 0, 1}]
Out[526]= 0.965749

or define H to use Integrate instead of NIntegrate. (Again, these are alternatives, using _?NumberQ for the arguments of H is the right answer.)
POSTED BY: Anton Antonov
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract