No BSD License  

Highlights from
MULTINOMIAL

3.0

3.0 | 4 ratings Rate this file 9 Downloads (last 30 days) File Size: 1.79 KB File ID: #6156

MULTINOMIAL

by Mukhtar Ullah

 

01 Nov 2004 (Updated 31 Jan 2005)

Multinomial coefficients.

| Watch this File

File Information
Description

MULTINOMIAL(N, K1, K2, ..., Km) where N and Ki are numeric arrays of non-negative integers satisfying N = K1 + K2 + ... + Km, returns the multinomial coefficient N!/( K1!* K2! ... *Km!).

MULTINOMIAL(N, [K1 K2 ... Km]) when Ki's are all scalar, returns the same as MULTINOMIAL(N, K1, K2, ..., Km).

Non-integer input arguments are pre-rounded by FLOOR function.

EXAMPLES:
multinomial(8, 2, 6) returns 28
binomial(8, 2) returns 28

multinomial(8, 2, 3, 3) returns 560
multinomial(8, [2, 3, 3]) returns 560

multinomial([8 10], 2, [6 8]) returns [28 45]

MATLAB release MATLAB 7 (R14)
Other requirements uses scalarexpand.m(by the same author) available in this file-exchange.
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (6)
26 Jan 2005 Antonio Trujillo-Ortiz

As a user, it is frustrating to run this function due that we get several ERROR display messages and abort function. Such as:

Undefined function or variable 'isfloat'.

Error in ==> C:\Documents and Settings\multinomial.m
On line 29 ==> if ~isreal(n) || ~isfloat(n) || any(n(:)<0)

??? Undefined function or variable 'sclrexpnd'.

Error in ==> C:\Documents and Settings\multinomial.m
On line 42 ==> [arg2{:},sizk] = sclrexpnd(arg2{:});

This last ERROR message is due that you have already created the m-file called scalarexpand not sclrexpnd.

Besides,there exists a much more parsimoniously way to calculate it you can find on this same site as multcoef.

So the users became frustrated.

27 Jan 2005 Mukhtar Ullah

ISFLOAT is a built-in function in MATLAB 7. For earlier versions, ~isfloat(n) can be replaced by ~isa(n,'double') | ~isa(n,'single').
I have renamed scalarexpand to fix the bug.
Thanks once again to Antonio Trujillo-Ortiz.

27 Jan 2005 Mukhtar Ullah

Another problem that can be faced by earlier versions is the short-circuit AND and OR functions (&&, ||). These can simple be replaced by the usual AND,OR (&,|).

06 Dec 2005 Min Poh

The update addresses the bugs mentioned in the comments. The function is also well documented.

03 Dec 2010 George richardson

well documented, simple function

20 Sep 2011 Kammoun

good work

Please login to add a comment or rating.
Updates
04 Nov 2004

code vectorized

17 Jan 2005

a minor correction

31 Jan 2005

a minor improvement: replace round with floor

Tag Activity for this File
Tag Applied By Date/Time
statistics Mukhtar Ullah 22 Oct 2008 07:34:33
probability Mukhtar Ullah 22 Oct 2008 07:34:33
coefficient Mukhtar Ullah 22 Oct 2008 07:34:34
multinomial Mukhtar Ullah 22 Oct 2008 07:34:34
nonnegative Mukhtar Ullah 22 Oct 2008 07:34:34
integers Mukhtar Ullah 22 Oct 2008 07:34:34

Contact us at files@mathworks.com