Adds two TT-tensors in TT1 format. [TT_RES]=TT_ADD(TT1,TT2) - adds two tensors in TT1.0 format. Please avoid the usage: it will be removed from future releases. Use the object-oriented version. 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 [tt_res] = tt_add(tt1,tt2) 0002 %Adds two TT-tensors in TT1 format. 0003 % [TT_RES]=TT_ADD(TT1,TT2) - adds two tensors in TT1.0 format. Please 0004 % avoid the usage: it will be removed from future releases. Use the 0005 % object-oriented version. 0006 % 0007 % 0008 % TT-Toolbox 2.2, 2009-2012 0009 % 0010 %This is TT Toolbox, written by Ivan Oseledets et al. 0011 %Institute of Numerical Mathematics, Moscow, Russia 0012 %webpage: http://spring.inm.ras.ru/osel 0013 % 0014 %For all questions, bugs and suggestions please mail 0015 %ivan.oseledets@gmail.com 0016 %--------------------------- 0017 0018 0019 0020 d=size(tt1,1); 0021 tt_res=cell(d,1); 0022 tt_res{1}=[tt1{1} tt2{1}]; 0023 tt_res{d}=[tt1{d} tt2{d}]; 0024 0025 for i=2:d-1 0026 core1=tt1{i}; 0027 core2=tt2{i}; 0028 ncur=size(core1,1); 0029 r21=size(core1,2); 0030 r31=size(core1,3); 0031 r22=size(core2,2); 0032 r32=size(core2,3); 0033 core=zeros(ncur,r21+r22,r31+r32); 0034 core(1:ncur,1:r21,1:r31)=core1; 0035 core(1:ncur,(r21+1):(r21+r22),(r31+1):(r31+r32))=core2; 0036 tt_res{i}=core; 0037 end 0038 return 0039 end