Re: variable dimension of domain of integration
- To: mathgroup at smc.vnet.net
- Subject: [mg115981] Re: variable dimension of domain of integration
- From: Daniel Lichtblau <danl at wolfram.com>
- Date: Fri, 28 Jan 2011 06:13:47 -0500 (EST)
Ulvi Yurtsever wrote:
> Consider the function $f(n) = \int_{{0,1}^n}
> \sqrt{\sum_{i=1}^{n} {x_i}^2} dx_1 ... dx_n$.
> How would you define a mathematica function
> F[n_] (using NIntegrate) that computes this
> integral over the n-cube? I can think of several
> inelegant solutions; but surely there are neat
> ways of doing things of this sort...
>
> thanks
One possibility:
f[n_] := Module[
{dims,x},
dims = Array[x,n];
NIntegrate[Evaluate[Sqrt[dims.dims]],
Evaluate[Sequence@@Map[{#,0,1}&,dims]]]
]
f[4]
Out[20]= 1.1219
Daniel Lichtblau
Wolfram Research