You're given three $n$-dimensional real vectors, $\mathbf{x_0}$, $\mathbf{a}$ and $\mathbf{b}$, with $\mathbf{a} \le \mathbf{x_0} \le \mathbf{b}$ (vector inequality means component-wise inequality). Starting at $\mathbf{x_0}$, simulate a bounded continuous random walk, such that the end point $\mathbf{x}$ of the walk is always inside the bounds $\mathbf{a} \le \mathbf{x} \le \mathbf{b}$.
I want to program this with Mathematica. The parameters of the simulation are the bounds $\mathbf{a}, \mathbf{b}$, the starting point $\mathbf{x_0}$, and a parameter $\sigma$ that controls the standard deviation of the step size. What's a simple and efficient way to do this?
Here's what I've tried:
The following function Walk
takes a vector $\mathbf{x}$ and returns the next point on the random walk.
Walk[x_List, a_List, b_List, sigma_] :=
x + RandomVariate[
TruncatedDistribution[Transpose[{a - x, b - x}],
MultinormalDistribution[ConstantArray[0, Length[x]],
sigma*IdentityMatrix[Length[x]]]]]
For some reason this is exceedingly slow. You can try it yourself. After executing:
a = ConstantArray[0, 10];
b = ConstantArray[1, 10];
x = RandomReal[{0, 1}, 10];
The following line of code takes forever on my PC:
Walk[x, a, b, 4]
Why?