Expand multi-index derivative
function S = expand_multiindex_derivative(M,P)
This function returns the derivative of multi-index expansion for the multi-index pair over the column vectors in the matrix , where the coefficients and corresponding multi-indices$\mathbf{C},\mathbf{I}$ are fields of the data structure M.
if isempty(M.ind) S = 0; else nt = size(P,2); C = M.coeffs; I = M.ind; n_I = size(I,1); dimSys = size(C,1); dimSSM = size(I,2); S = zeros(dimSys,dimSSM,nt); for i=1:n_I coeff = C(:,i); ind = I(i,:)'; % find nonzero exponents expind = find(ind); pind = P(expind,:); pind(pind==0) = eps; % handle divided by zero s = prod(pind.^ind(expind),1); s = (ind(expind)./pind).*s; % #p X nt s = s.'; s = s(:); s = s.'; s = coeff.*s; s = reshape(full(s),[dimSys,nt,numel(expind)]); s = permute(s,[1,3,2]); S(:,expind,:) = S(:,expind,:)+ s; end end
end