Function File: [y alpha] = multinom (x, n)
Function File: [y alpha] = multinom (x, n,sort)
Returns the terms (monomials) of the multinomial expansion of degree n.
(x1 + x2 + ... + xm)^nx is a nT-by-m matrix where each column represents a different variable, the output y has the same format. The order of the terms is inherited from multinom_exp and can be controlled through the optional argument sort and is passed to the function
sort
. The exponents are returned in alpha.
The following code
n = 3; t = linspace(-1,1,10).'; x = [t-1/2, t]; y = multinom(x,n,'descend'); y_shouldbe = [x(:,1).^3 x(:,2).^3 x(:,1).^2.*x(:,2) x(:,1).*x(:,2).^2 ]; plot(t,y_shouldbe); hold on; plot(t,y,'s'); hold off; legend('x_1^3','x_2^3','x_1^2x_2','x_1x_2^2','location','southoutside',... 'orientation','horizontal'); title('Terms of the expansion of (x_1 + x_2)^3 (colors should match)');
Produces the following figure
Figure 1 |
---|
Package: specfun