0
$\begingroup$

What is the best way to evaluate coupled integrations using NIntegrate? For eaxmple for the following function,

func = f[x2]*g[x1]

with (for demonstration),

f[x2]=x2 and g[x1]=x1

which I want to integrate from x1->{x2,1} and x2->{0,1}. Note that the x1 integration starts from x2.

test1=Integrate[f[x2]*Integrate[g[x1],{x1,x2,1}],{x2,0,1}] (*Analytic*)
test2=NIntegrate[f[x2]*NIntegrate[g[x1],{x1,x2,1}],{x2,0,1}] (*Numerical*)

test2 in fact gives correct result (0.125 in this case), however it also comes with the following error:

NIntegrate::nlim: x1 = x2 is not a valid limit of integration.

Can anyone suggest to do this kind of numerical integration in efficient way?

$\endgroup$
  • 1
    $\begingroup$ Integrate[x1 x2, {x2, 0, 1}, {x1, x2, 1}]? $\endgroup$ – eyorble May 9 '18 at 16:19
  • $\begingroup$ NIntegrate[x1 x2, {x2, 0, 1}, {x1, x2, 1}] gives correct result without error. But what is the problem if I do NIntegrate[x1 x2, {x1, x2, 1},{x2, 0, 1}] ? $\endgroup$ – Boogeyman May 9 '18 at 16:22
  • $\begingroup$ The earlier integration ranges precede the definitions of the later integration ranges, and thus cannot depend on them. $\endgroup$ – eyorble May 9 '18 at 16:26
  • $\begingroup$ Sorry, but x1 integration is done first no? I wonder why NIntegrate[f[x2]*NIntegrate[g[x1],{x1,x2,1}],{x2,0,1}] shows error where the ordering is as it should be. $\endgroup$ – Boogeyman May 9 '18 at 16:40
  • $\begingroup$ No, in Integrate the integration is done in the order that the integration ranges are specified. Without nested integrals, so long as the space of integration is the same the integral itself is the same. With nested integrals, it's a question of if the phase space is actually the same, but considering that they're separable (x1 and x2 are independent), they are, so it is. In the integration command you mention though, x2 is done first since it's on the outside. $\endgroup$ – eyorble May 9 '18 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.