2
$\begingroup$

If I try to input a symbolic multivariate distribution, I do not get a useful result.

PDF[MultinormalDistribution[m, S], x] (* During evaluation of MultinormalDistribution::vrprm: The value m at position 1 in MultinormalDistribution[m,S] is expected to be a list of real numbers. *) (* During evaluation of MultinormalDistribution::vrprm: The value m at position 1 in MultinormalDistribution[m,S] is expected to be a list of real numbers.*) (* PDF[MultinormalDistribution[m, S], x] *) 

Clearly, Mathematica could return an appropriate symbolic expression. Is there any way of making it do so?

$\endgroup$

1 Answer 1

8
$\begingroup$

You need to supply Mathematica with the structure of your variables:

(* dimension of distribution *) n = 2; PDF[ MultinormalDistribution[ Array[Subscript[m, ##] &, n], Array[Subscript[S, Sequence @@ Sort@{##}] &, {n, n}] ], Array[Subscript[x, ##] &, n] ] 

enter image description here We use Array to construct variables of the form Subscript[var,i,j,…] (you can of course use any other form that is more convenient). Note that S is explicitly made symmetric by sorting the indices. The code works without this, but this way there are no "fake" parameters.

Note: As pointed out by @BobHanlon in the comments, Subscript can often cause issues if used blindly. For actual use, it is much safer to simply use indexed variables such as Array[x, n].

$\endgroup$
5
  • $\begingroup$ Rather than using subscripted variables, I recommend using indexed variables and then using Format to display the indexed variables as subscripted variables. Subscripted variables tend to cause problems in solvers. $\endgroup$ Commented Apr 27, 2019 at 12:59
  • $\begingroup$ I am aware of that - I just thought that for a quick demonstration, it would be good enough and it's easy to read. But I will add a comment to the answer to point out potential issues. $\endgroup$ Commented Apr 27, 2019 at 13:03
  • $\begingroup$ A very useful answer, but I was hoping for an expression that worked in terms of vector and matrix inputs (of unspecified dimension). $\endgroup$ Commented Apr 27, 2019 at 13:32
  • $\begingroup$ @BobHanlon is there an answer you can link to that would detail an appropriate use of the Format method you reference? $\endgroup$ Commented Apr 29, 2019 at 14:01
  • 2
    $\begingroup$ @CATrevillian - For a simple example, consider Format[x[n_]] := Subscript[x, n]; x /@ {m, n, 1, 2, 3} Also see documentation details section and link $\endgroup$ Commented Apr 29, 2019 at 16:12

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.