# A function calculating a multiple integral and taking multiplicity as a parameter

I have a function of the following form:
φn(x)=∫R…∫R⏟nexp[−n∑j=2(xj−xj−1)2−(x−xn)2]dx1…dxn(φn(x)≡πn/2),

and I’m trying to define a function Phi[x, n] that will calculate the above integral. I know, how to define this function for fixed nn, for example
φ1(x)=∫Re−(x−x1)2dx1,
\varphi_1(x)= \int\limits_\mathbb{R}e^{-(x-x_{1})^2}dx_1,

defines as

Phi1 = Integrate[Exp[-(x – #)^2], {x, -Infinity, Infinity}] &;

and
φ2(x)=∫R∫Re−(x2−x1)2−(x−x2)2dx1dx2,
\varphi_2(x)= \int\limits_\mathbb{R}\int\limits_\mathbb{R}e^{-(x_2-x_1)^2-(x-x_2)^2}dx_1dx_2,

defines as

Phi2 = Integrate[Integrate[Exp[-(x2 – x1)^2 – (# – x2)^2], {x1, -Infinity, Infinity}], {x2, -Infinity, Infinity}] &;

How to define a function, that would take nn as an argument?

=================

=================

3

=================

I bet you could do this more elegantly with Fold, but this gets you there,

Phi[n_] :=
Integrate[Exp[-Sum[(x[j] – x[j – 1])^2, {j, 2, n}] – (x – x[n])^2],
Sequence @@ ({x[#], -âˆž, âˆž} & /@ Range[n])]

Phi /@ Range[5]
(* {Sqrt[Ï€], Ï€, Ï€^(3/2), Ï€^2, Ï€^(5/2)} *)

You could make it a function of x, but as you write, the answer is independent of x so I don’t see why you would.

@Glinka In order to obtain a true dependence on x you could change the integration interval. (Although the integral might not be solved symbolically anymore).
– Dr. Wolfgang Hintze
Mar 16 at 15:47

@JasonB, thank you for your answer! Your method worked on the example from the question, and it worked when I used a function that actually depended on xx. The problem though that it works very slow when n>3n>3 (for n=3n=3 the process lasts several minutes and for n=4n=4 the process doesn’t seem to end). I figured that I use NIntegrate instead of Integrate, it would speed up a process. But when I just change Integrate to NIntegrate in your code, it show the following error: Invalid integration variable or limit(s) in {x[1],-[Infinity],[Infinity]}. What do I do wrong?
Mar 16 at 19:03

@Glinka It’s true that multidimensional integrals can take a while, and can be sped up by using numerical methods. But it’s hard to fix an error without having the code to reproduce it. You could post it here as a comment or as another question.
– JasonB
Mar 16 at 19:07

@Dr.WolfgangHintz, in our task we always consider integrals over R\mathbb{R}, and a true dependence on x occurs when we consider more complex integrands. In the example from the question xx variable is dummy by accident.
Mar 16 at 19:12

@JasonB, I posted it as a new question: mathematica.stackexchange.com/questions/110197/…
Mar 16 at 19:36

My take:

With[{n = 6},
Integrate[Exp[-#.# & @ Differences[Append[Array[C, n], x]]], ##] & @@
Array[{C[#], -âˆž, âˆž} &, n]]

Here’s some silliness along the lines of Jason B’s answer:

int[n_]:= Integrate[
Exp[-#^2] &@*Subtract @@@ Partition[Array[x, n + 1, 0], 2, 1] // Times @@ # &,
Sequence @@ Array[{x[#], -âˆž, âˆž} &, 3]
]