function [prob] = DirichletDistribution(alpha, Q, P)
%[prob] = DirichletDistribution(alpha, Q, P)
%   Evaluate the density function of the Dirichlet distribution
%   with parameters alpha (scalar) and Q (vector) at P (vector of
%   same size as Q) and return the scalar result. 
%   ($RCSfile: DirichletDistribution.m,v $ $Revision: 1.1.1.1 $)

%%% Check arguments:
P=P(:);Q=Q(:); alpha=alpha(1,1);
if ( sum([ P; Q; alpha] <0) )
  error('DirichletDistribution: arguments must be nonnegative.')
end
if ( (sum(P) ~= 1) || (sum(Q) ~= 1) )
  error('DirichletDistribution: Sum of P and Q must be equal to 1.')
end
if ( length(P)~=length(Q) )
  error('DirichletDistribution: P and Q must have same length.')
end
%%% Do computation:
prob=gamma(alpha)/prod(gamma(alpha*Q))*prod(P.^(alpha*Q-1));
return;