TITLE: find $ \int_0^4\int_0^4\int_0^4 \sqrt{x^2+y^2+z^2}\,dx\,dy\,dz$
QUESTION [8 upvotes]: I am looking for an approximation to the nearest integer of
$$ \int_0^4\int_0^4\int_0^4 \sqrt{x^2+y^2+z^2}\,dx\,dy\,dz.$$
Wolfram alpha gives up and says "computation time exceeded".
I tried, unsuccessfully, to approximate the measure of the sets
$$ E_N = \{(x,y,z):x,y,z\in[0,4],\; x^2+y^2+z^2\in[N,N+1]\},$$
but in some cases the volume of the intersection between a cube and a spherical shell is very hard to compute.

REPLY [9 votes]: $\newcommand{\+}{^{\dagger}}
 \newcommand{\angles}[1]{\left\langle\, #1 \,\right\rangle}
 \newcommand{\braces}[1]{\left\lbrace\, #1 \,\right\rbrace}
 \newcommand{\bracks}[1]{\left\lbrack\, #1 \,\right\rbrack}
 \newcommand{\ceil}[1]{\,\left\lceil\, #1 \,\right\rceil\,}
 \newcommand{\dd}{{\rm d}}
 \newcommand{\down}{\downarrow}
 \newcommand{\ds}[1]{\displaystyle{#1}}
 \newcommand{\expo}[1]{\,{\rm e}^{#1}\,}
 \newcommand{\fermi}{\,{\rm f}}
 \newcommand{\floor}[1]{\,\left\lfloor #1 \right\rfloor\,}
 \newcommand{\half}{{1 \over 2}}
 \newcommand{\ic}{{\rm i}}
 \newcommand{\iff}{\Longleftrightarrow}
 \newcommand{\imp}{\Longrightarrow}
 \newcommand{\isdiv}{\,\left.\right\vert\,}
 \newcommand{\ket}[1]{\left\vert #1\right\rangle}
 \newcommand{\ol}[1]{\overline{#1}}
 \newcommand{\pars}[1]{\left(\, #1 \,\right)}
 \newcommand{\partiald}[3][]{\frac{\partial^{#1} #2}{\partial #3^{#1}}}
 \newcommand{\pp}{{\cal P}}
 \newcommand{\root}[2][]{\,\sqrt[#1]{\vphantom{\large A}\,#2\,}\,}
 \newcommand{\sech}{\,{\rm sech}}
 \newcommand{\sgn}{\,{\rm sgn}}
 \newcommand{\totald}[3][]{\frac{{\rm d}^{#1} #2}{{\rm d} #3^{#1}}}
 \newcommand{\ul}[1]{\underline{#1}}
 \newcommand{\verts}[1]{\left\vert\, #1 \,\right\vert}
 \newcommand{\wt}[1]{\widetilde{#1}}$
With
$\ds{\pars{~\mbox{spherical coordinates}~}\ r = \root{x^{2} + y^{2} + z^{2}}}$, we have
$\ds{\nabla\cdot\pars{r\,\vec{r}} = {\vec{r} \over r}\cdot\vec{r} + 3r = 4r}$:

\begin{align}&\int_{0}^{4}\int_{0}^{4}\int_{0}^{4}%
\root{x^{2} + y^{2} + z^{2}}\,\dd x\,\dd y\,\dd z
=\int_{\bracks{0,4}^{3}}r\,\dd^{3}\vec{r}
=\int_{\bracks{0,4}^{3}}{1 \over 4}\,\nabla\cdot\pars{r\,\vec{r}}\,\dd^{3}\vec{r}
\\[3mm]&={1 \over 4}\int_{\rm S}r\,\vec{r}\cdot\dd\vec{\rm S}
={1 \over 4}\int_{\braces{0,4}^{2}}\root{16 + y^{2} + z^{2}}\,4\,\dd y\,\dd z
\\[3mm]&+{1 \over 4}\int_{\braces{0,4}^{2}}\root{x^{2} + 16 + z^{2}}\,4
\,\dd x\,\dd z
+{1 \over 4}\int_{\braces{0,4}^{2}}\root{x^{2} + y^{2} + 16}\,4\,\dd x\,\dd y
\end{align}

\begin{align}&\int_{0}^{4}\int_{0}^{4}\int_{0}^{4}%
\root{x^{2} + y^{2} + z^{2}}\,\dd x\,\dd y\,\dd z
=3\int_{\braces{0,4}^{2}}\root{x^{2} + y^{2} + 16}\,\dd x\,\dd y
\\[3mm]&=3\int_{0}^{4}\int_{0}^{4}\root{x^{2} + y^{2} + 16}\,\dd y\,\dd x
=192\int_{0}^{1}\int_{0}^{1}\root{x^{2} + y^{2} + 1}\,\dd y\,\dd x
\\[3mm]&=48\int_{0}^{1}\left\{2\left[\root{x^{2} + 2} + \left(x^{2} + 1\right)
\ln\left(\root{x^{2} + 2} + 1\right)\right] - \left(x^{2} + 1\right)
\ln\left(x^{2} + 1\right)\right\}\,\dd x
\\[3mm]&=\bbox[15px,border:1px solid navy]{\ds{
64\left[\root{3} + \ln\left(7 + 4\root{3}\right)\right] - {32\pi \over3}}}
\approx {\tt 245.9115409}
\end{align}

// monteCarlo0.cc
#include <cmath>
#include <cstdlib>
#include <iomanip>
#include <iostream>
using namespace std;
typedef long double ldouble;
typedef unsigned long long ullong;
const ldouble RANDMAX1=ldouble(RAND_MAX) + 1.0L;
const ullong ITER=100000000ULL; // One hundred million
ldouble X,Y;

inline ldouble f(ldouble x,ldouble y)
{
 return sqrt(x*x + y*y + 1.0L);
}

inline ldouble f()
{
 X=rand()/RANDMAX1;
 Y=rand()/RANDMAX1;
 return (f(X,Y) + f(X,1.0L - Y) + f(1.0L - X,Y) + f(1.0L - X,1.0L - Y))/4.0L;
}

int main()
{
 ldouble suma=0;

 for ( ullong n=0 ; n<ITER ; ++n ) suma+=f();
 cout<<setprecision(50)<<(192.0L*(suma/ITER))<<endl;

 return 0;
}

It runs for 7 sec.
Result: $\ds{\color{#f00}{ 245.911}07650843407733676215798368502873927354812622}$.