Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I would like to plot the multinomial beta from the Dirichlet Distribution wiki page.

$$\mathrm{B}(\alpha) = \frac{\prod_{i=1}^K \Gamma(\alpha_i)}{\Gamma\bigl(\sum_{i=1}^K \alpha_i\bigr)},\qquad\alpha=(\alpha_1,\dots,\alpha_K)$$

Looking at the equation, the only input should be a vector of alphas of size $K$.

What Octave/Matlab function(s) should I use? I found the following Matlab beta function, but it seems to be only for $K=2$.

share|cite|improve this question
up vote 1 down vote accepted

You can use the gamma and gammaln in MATLAB to directly compute the expression you have. I would recommend gammaln since you will have very big numbers, and the logarithmic form avoids computing the ratio of big numbers.

Also, if you want to sample from Dirichlet, you can generate bunch of gamma random variables using gamrnd (in statistics toolbox) and then normalize.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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