Multi-index to tensor
Contents
function [T] = multi_index_to_tensor(C,I)
MULTI_INDEX_TO_TENSOR
This function returns the multi-dimensional array for given multi-index coefficients and the corresponding exponents
Inputs:
- : Array containing multi-index coefficients
- : Array containing multi-index exponents
Outputs:
- : -dimensional arraty in the form of sptensor object (cf. tensor toolbox)
Other variables:
- degree of tensor polynomial (currently only uniform single degree supported currently
- The numer of variables in the multivariate polynomial
Assuming the tensor array acts on the vector along the dimensions . We have the following relationship between the input and output
or
,
where the different arrays are organized in the following form:
, where the i-th row represents the coefficients ,
is a matrix whose rows contain the multi-indices respresented by the tensor ,
.
n = size(C,1); d = sum(I(1,:)); r = size(I,2); nSubs = size(I,1); SIZE = [n r*ones(1, d)]; SUBS = zeros(nSubs,d); for j = 1:nSubs p = I(j,:); SUBS(j,:) = multi_index_to_sub(p); end [i,j,VALS] = find(sparse(C)); T = sptensor([i, SUBS(j,:)],VALS,SIZE);
end
function subs = multi_index_to_sub(p) d = sum(p); subs = zeros(1,d); [~, i, s] = find(p); m = 1; for k = 1:d subs(k) = i(m); if s(m) == 1 m = m + 1; else s(m) = s(m) - 1; end end end