# How do I divide an integral into parts and sum the total?

I have an exercise looking like this: Analyze the integral $$4\int_{0}^{1} \sqrt{1-x^2} \, \mathrm{d} x$$ numerically by deviding the interval $${]0,1[}$$ into three equal parts, then summarize the integral parts.

I just can't get it to work. I tried to make tables, sum functions, Integrate functions but i can just make it the normal way like this: Integrate[4 (Sqrt[(1 - x^2)]), {x, 0, 1}].

Any help

Create a function that returns a list of adjacent intervals in $$[0,1]$$:

ClearAll[intervals]
intervals[n_] := Partition[Subdivide[0, 1, n], 2, 1]

For instance:

intervals[3]

Then numerically integrate your function over all those intervals:

partials = NIntegrate[4 (Sqrt[(1 - x^2)]), {x, #1, #2}] & @@@ intervals[3]

(* {1.30821, 1.14505, 0.688329} *)

The total is $$\pi$$, as should be from the overall integral:

Total[partials]
(* Out: 3.14159 *)

You can now divide the range up into however many subintervals:

NIntegrate[4 (Sqrt[(1 - x^2)]), {x, #1, #2}] & @@@ intervals[15]

{0.266469, 0.26528, 0.262885, 0.259252, 0.254327, 0.248033, 0.240262, 0.230864, 0.219631, 0.206261, 0.190302, 0.171025, 0.147111, 0.115629, 0.0642622}

and of course the sum is still the same.

Note that I am using numerical integration here (i.e. NIntegrate) because the symbolic integration can be quite slow even for a simple function. If you want analytical results, use Integrate instead, but beware of long execution times!

symbolic = Integrate[4 (Sqrt[(1 - x^2)]), {x, #1, #2}] & @@@ intervals[3]

and the total is $$\pi$$ as expected, after some simplification:

Simplify@Total[symbolic]

(* Out: π *)