1
$\begingroup$

The following expression works correctly:

Expectation[
 x^4, {x, y, z} \[Distributed] 
  MultinormalDistribution[{0, 0, 0}, IdentityMatrix[3]]]

But when I replace {x,y,z} by a vector v:

ClearAll[v];
Expectation[v[[1]]^4, 
 v \[Distributed] 
  MultinormalDistribution[{0, 0, 0}, IdentityMatrix[3]]]

I get the following error message:

Part::partd: Part specification v[[1]] is longer than depth of object.

Is there a way to use a vector variable in such an expression ?

$\endgroup$
1
$\begingroup$
ClearAll[v, vv];
v = Array[vv, 3];
Expectation[v[[1]]^4,  v \[Distributed] 
   MultinormalDistribution[{0, 0, 0}, IdentityMatrix[3]]]

3

Or

Expectation[vv[1]^4, 
 v \[Distributed]  MultinormalDistribution[{0, 0, 0}, IdentityMatrix[3]]]

3

$\endgroup$
0
$\begingroup$

You wrote:

But when I replace {x,y,z} by a vector v:

ClearAll[v]; Expectation[v[[1]]^4, v \[Distributed]
MultinormalDistribution[{0, 0, 0}, IdentityMatrix[3]]]

I get the following error message:....

The essence of why this didn't work is that, in the above syntax, you actually didn't replace {x,y,z} by a vector v, because you did not define v as a vector. If we do define v as a vector, it works:

ClearAll[v];
v = {x, y, z};
Expectation[v[[1]]^4, 
v \[Distributed] 
MultinormalDistribution[{0, 0, 0}, IdentityMatrix[3]]]

3

In particular, the reason you got that specific error message is because you were asking Mathematica to return the first indexed part of an undefined variable, and an undefined variable doesn't have any indexed parts. However, if you define v as, say, the vector {x, y, z} (an object consisting of three indexed parts), then when you ask Mathematica to return v[[1]], it will return the first indexed part of v, which is x.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.