mnpdf
Multinomial probability density function
Syntax
Description
Examples
Compute the pdf of a multinomial distribution with a sample size n. The probabilities are 1/2 for the first outcome, 1/3 for the second outcome, and 1/6 for the third outcome.
p = [1/2 1/3 1/6]; n = 10; x1 = 0:n; x2 = 0:n; [X1,X2] = meshgrid(x1,x2); X3 = n-(X1+X2);
Compute the pdf of the distribution.
Y = mnpdf([X1(:),X2(:),X3(:)],repmat(p,(n+1)^2,1));
Plot the pdf on a 3-dimensional figure.
Y = reshape(Y,n+1,n+1); bar3(Y) h = gca; h.XTickLabel = [0:n]; h.YTickLabel = [0:n]; xlabel("x_1") ylabel("x_2") zlabel("Probability Mass") title("Trinomial Distribution")

Note that the visualization does not show x3, which is determined by the constraint x1 + x2 + x3 = n.
Input Arguments
Evaluation points, specified as a 1-by-k numeric vector or an
m-by-k numeric matrix, where
k is the number of multinomial bins or categories. The sample sizes
for each observation (rows of x) are given by the row sums
sum(x,2).
xmust have the same number of columns asP.If
xis a 1-by-k vector, thenmnpdfreplicatesxinto a matrix that has the same number of rows asP.If
xandPare matrices, they must have the same number of rows.
Data Types: single | double
Outcome probabilities, specified as one of the following, where k
is the number of multinomial bins or categories. P must have the
same number of columns as x, and must contain only nonnegative
scalar values.
A k-by-1 vector that sums to 1. In this case,
mnpdftransposesPinto a 1-by-k vector.A 1-by-k vector. If
xis a matrix, thenmnpdfreplicatesPinto a matrix with the same number of rows asx.A j-by-k matrix, where each row corresponds to a multinomial probability distribution. If
xis a matrix, thenPandxmust have the same number of rows.
If a row of P does not sum to 1, the corresponding row in
y is NaN.
Data Types: single | double
Output Arguments
pdf values, returned as a numeric column vector with the same number of rows as
P. mnpdf computes each row of
y using the corresponding rows of the inputs. If a row of
P does not sum to 1, the corresponding row in
y is NaN.
Extended Capabilities
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Version History
Introduced in R2006b
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Seleccione un país/idioma
Seleccione un país/idioma para obtener contenido traducido, si está disponible, y ver eventos y ofertas de productos y servicios locales. Según su ubicación geográfica, recomendamos que seleccione: .
También puede seleccionar uno de estos países/idiomas:
Cómo obtener el mejor rendimiento
Seleccione China (en idioma chino o inglés) para obtener el mejor rendimiento. Los sitios web de otros países no están optimizados para ser accedidos desde su ubicación geográfica.
América
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)