% contract the d-th dimension of tensor t with the vector v to produce % a matrix function a = tcontract(t,v,d) tdim = tdimensions(t); adim = []; for p=1:3, if p ~= d, adim = [adim tdim(p)]; end end a = zeros(adim); for s=1:tdim(d), a = a + v(s)*tgetmatrix(t,s,d); end