# Symbolic Multivariate Distribution

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?

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]
]


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].

• 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. – Bob Hanlon Apr 27 '19 at 12:59
• 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. – Lukas Lang Apr 27 '19 at 13:03
• A very useful answer, but I was hoping for an expression that worked in terms of vector and matrix inputs (of unspecified dimension). – mikado Apr 27 '19 at 13:32
• @BobHanlon is there an answer you can link to that would detail an appropriate use of the Format method you reference? – CA Trevillian Apr 29 '19 at 14:01
• @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 – Bob Hanlon Apr 29 '19 at 16:12