I have a complicated function $f(x)$ whose analytical form does not exist for the following integral $$g(x)=\int_0^x\mathrm{d}x'\,f(x'). $$ I finally need to evaluate the following integral $$\int_0^a\mathrm{d}x\,g(x)~,$$ where $a$ is some finite real number like 1000. Therefore, essentially I need two NIntegrate. However, NIntegrate needs finite integration limit, not some abstract $x$. How do I deal with this problem?
1 Answer
This can be written down as the parametric iterated integral $$I(a)=\int_0^a\left( \int_0^x f(y)\mathrm dy\right) \mathrm dx$$ NIntegrate supports the syntax
NIntegrate[f,{x,xm,xM},{y,ym,yM}]
(where $x_m,x_M$ are the bounds of the outer integral, $y_m,y_M$ of the inner one) to compute this kind of integrals. This means that you can evaluate your result numerically through the following line of code:
I[a_]:=NIntegrate[f[y],{x,0,a},{y,0,x}]
Just substitute your favourite $f(y)$ inside to obtain the result: mine is
In: I1[a_]:=NIntegrate[1,{x,0,a},{y,0,x}];
In: I1[1]
Out: 0.5
NIntegrate[f[y], {x, 0, a}, {y, 0, x}]
? $\endgroup$NIntegrate
. $\endgroup$Integrate[(a - x) f[x], {x, 0, a}] == Integrate[f[x], {y, 0, a}, {x, 0, y}]
$\endgroup$