function covariance = multinomial_covariance ( a, b, c )

%*****************************************************************************80
%
%% multinomial_covariance() returns the covariances of the multinomial PDF.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    16 September 2004
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer A, the number of trials.
%
%    integer B, the number of outcomes possible on one trial.
%    1 <= B.
%
%    real C(B).  C(I) is the probability of outcome I on
%    any trial.
%    0.0 <= C(I) <= 1.0,
%    Sum ( 1 <= I <= B) C(I) = 1.0.
%
%  Output:
%
%    real COVARIANCE(B,B), the covariance matrix.
%
  for i = 1 : b
    for j = 1 : b

      if ( i == j )
        covariance(i,j) = a * c(i) * ( 1.0 - c(i) );
      else
        covariance(i,j) = - a * c(i) * c(j);
      end

    end
  end

  return
end
