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.
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:
+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.)
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!).