0
|
12598 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
GROUPS:

# Numerical integration of a function defined by numerical integration

Posted 10 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 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 result0.965749How can I get rid of the warnings? There is obvious something that Mathematica 9 does not like in this construction.
3 Replies
Sort By:
Posted 10 years ago
 Alternatively, you can just evaluateIn:= NIntegrate[F[1, b, c], {b, 0, 2}, {c, 0, 1}]Out= 0.965749or define H to use Integrate instead of NIntegrate. (Again, these are alternatives, using _?NumberQ for the arguments of H is the right answer.)
Posted 10 years ago
 In:= 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}];GOut= 0.965749
Posted 10 years ago
 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 tipsIf 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.