Computes X in the QTT-format [RES]=TT_X(N,D), or [RES]=TT_X(N): Vector with elements 0:N(1)*...*N(D)-1 is transformed into a tensor of size N(1) x N(2) x ... x N(D) This function returns its TT-decomposition with rank 2 This function is useful for the computation of the QTT-decomposition of the function y=x TT-Toolbox 2.2, 2009-2012 This is TT Toolbox, written by Ivan Oseledets et al. Institute of Numerical Mathematics, Moscow, Russia webpage: http://spring.inm.ras.ru/osel For all questions, bugs and suggestions please mail ivan.oseledets@gmail.com ---------------------------
0001 function [res]=tt_x(n,varargin) 0002 %Computes X in the QTT-format 0003 % [RES]=TT_X(N,D), or [RES]=TT_X(N): Vector with elements 0004 % 0:N(1)*...*N(D)-1 is transformed into a tensor of size 0005 % N(1) x N(2) x ... x N(D) 0006 % This function returns its TT-decomposition with rank 2 0007 % This function is useful for the computation of the QTT-decomposition 0008 % of the function y=x 0009 % 0010 % 0011 % TT-Toolbox 2.2, 2009-2012 0012 % 0013 %This is TT Toolbox, written by Ivan Oseledets et al. 0014 %Institute of Numerical Mathematics, Moscow, Russia 0015 %webpage: http://spring.inm.ras.ru/osel 0016 % 0017 %For all questions, bugs and suggestions please mail 0018 %ivan.oseledets@gmail.com 0019 %--------------------------- 0020 if (numel(n) == 1) 0021 d=varargin{1}; 0022 n=n*ones(1,d); 0023 else 0024 d=numel(n); 0025 end 0026 0027 0028 0029 res=cell(d,1); 0030 0031 res{1}=ones(n(1),2); 0032 res{1}(:,1)=0:n(1)-1; 0033 0034 % shabl=zeros(n(1),2,2); 0035 % for j=1:n 0036 % shabl(j,:,:)=eye(2,2); 0037 % end 0038 ni=n(1); 0039 0040 for i=2:d-1 0041 shabl=zeros(n(i),2,2); 0042 for j=1:n(i) 0043 shabl(j,:,:)=eye(2,2); 0044 end 0045 0046 res{i}=shabl; 0047 res{i}(:,2,1)=ni.*(0:n(i)-1); 0048 ni=ni*n(i); 0049 end 0050 0051 res{d}=ones(n(d),2); 0052 res{d}(:,2)=ni.*(0:n(d)-1); 0053 0054 res = tt_tensor(res); % Bydlocode 0055 return 0056 end