# Numerical integration of a numerical integration [closed]

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?

• NIntegrate[f[y], {x, 0, a}, {y, 0, x}]? Commented Jul 18, 2016 at 13:37
• @J.M., There is a spelling mistake in NIntegrate. Commented Jul 18, 2016 at 13:40
• @J.M. That does not work: In[25]:= NIntegrate[Exp[-x], {x, 0, y}, {y, 0, 10}] Out[25]= NIntegrate[Exp[-x], {x, 0, y}, {y, 0, 10}] Commented Jul 18, 2016 at 13:45
• @titanium, look at my code carefully again, and note the order of the second and third arguments. Commented Jul 18, 2016 at 13:46
• For this case, you might use the identity Integrate[(a - x) f[x], {x, 0, a}] == Integrate[f[x], {y, 0, a}, {x, 0, y}] Commented Jul 18, 2016 at 22:18

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