Cummulative (dim 2) products across all permutations of distinct column-indices

版本 1.2.0.0 (4.0 KB) 作者: Hin Kwan Wong
Sum column element products for all permutations of distinct column indices + user restrictions
235.0 次下载
更新时间 2011/11/22

查看许可证

CUMmulative PRODucts across All Permutations of Distinct Column-Indices
This function returns the cumulative sum over products of column elements
with all permutations of unique and distinct column-indices.
The sum excludes automatically products containing elements with common
column index values. In addition, any user specified index values in
ignoredInd are excluded. (As all permutations of columns are summed, the
permutation of the columns of the input array is not important.)

For example, cumprodapdci([a,b],[1 7]) for vectors a and b is the sum of
sum(a.*b) minus all contributions of a(2)b(2), a(3)b(3) and the user
specified ignoredInd of 1 and 7, i.e. all products involving the elements
a(1),a(7),b(1) and b(7) are not included in the sum.

Example application:
For a vector K represnting the input values of a multinomial expansion of (K(1)+K(2)+K(3))^n, the result can be expressed as: sum(sum(...sum(K)*K)*K)...)

Alternatively, one can build up the expansion with product elements. For example, when n=4, the result is equal to the sum of all forms of:
x^4
+4*(sum of all forms of a*b^3)
+6*(sum of all forms of a^2*b^2)
+12*(all combinations of the form a*b*c^2.)
see http://www.wolframalpha.com/input/?i=expand%28a%2Bb%2Bc%29%5E4

Hence, if one is interested at all contributions of the form a^2*b^4 for n=6 for example, the answer is given as the multinomial coefficient 6!/2!/4! * sum of all combinations of the form a^2*b^4.

This can be performed by using this routine of cumproduei([K.^2,K^4]), where K is [a;b;c;d+...] as in the problem of (a+b+c+d+e+...)^6.
If one wants to ignore contributions containing terms K(3)=c and K(5)=e, one may use cumproduei([K.^2,K^4],[3,5]).

It is important to note that the result requires normalisation with the multinomial coefficient M, and the correction factor 1/prod(DoFs!). The implementation of M is available on file exchange from other authors.
E.g. 6156-multinomial, wheras the correction factor is described as follows:
If there are common column vector with common power, such is the case when n = 4 and one would like to sum all instances of the form a*b*c^2. The result should be normalised by multiplying the result with M/(products of factorials of DoF). M is the multinomial coefficient as mentioned before, and the degree of freedom refers to the number of variables with a common power. In this example, the common order is a & b and there are 2 of them. For a more complicated case, for example, a*b*c^4*d^4*e^6*f^6*g^6, the normalisation factor should be M/2!2!3!=M/24. Here, the multinomial coefficient M=(6+6+6+4+4+2)!/(6!6!6!4!4!2!).

引用格式

Hin Kwan Wong (2024). Cummulative (dim 2) products across all permutations of distinct column-indices (https://www.mathworks.com/matlabcentral/fileexchange/33620-cummulative-dim-2-products-across-all-permutations-of-distinct-column-indices), MATLAB Central File Exchange. 检索时间: .

MATLAB 版本兼容性
创建方式 R2010b
兼容任何版本
平台兼容性
Windows macOS Linux

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
版本 已发布 发行说明
1.2.0.0

Updated title

1.1.0.0

1. Vastly optimised and rewritten code (>200 times speed improvement)
2. Changed function name

1.0.0.0