0001 function [ttm] = tt_Fd_mtx(d_phys, tt_a, bound1, bound2, eps)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025 d = size(tt_a, 1);
0026 d1 = round(d/d_phys);
0027 dims = ones(1,d_phys-1);
0028 for i=1:d_phys-1
0029 dims(i) = d1*i;
0030 end;
0031 ranks = tt_ranks(tt_a);
0032 phys_ranks = ranks(dims);
0033 phys_j = ones(1, d_phys-1);
0034 first_comp=1;
0035
0036
0037 while (phys_j(d_phys-1)<=phys_ranks(d_phys-1))
0038
0039 for q=1:d_phys
0040 M = cell(d, 1);
0041 cur_a = cell(d1,1);
0042
0043 for k=1:d1-1
0044 cur_a{k}=tt_a{k};
0045 end;
0046 cur_a{d1} = tt_a{d1}(:,:,phys_j(1));
0047 if (q==1)
0048 cur_a = tt_Fd_mtx1(cur_a, bound1, bound2,eps);
0049 else
0050 cur_a = tt_diag_av1(cur_a, eps);
0051 end;
0052 for k=1:d1-1
0053 M{k}=cur_a{k};
0054 end;
0055 M{d1}(1:2,1:2,1:size(cur_a{d1}, 3),1)=reshape(cur_a{d1}, 2, 2, size(cur_a{d1}, 3), 1);
0056
0057
0058 for p=2:d_phys-1
0059 cur_a{1} = permute(tt_a{d1*(p-1)+1}(:,phys_j(p-1),:), [1 3 2]);
0060 for k=2:d1-1
0061 cur_a{k}=tt_a{d1*(p-1)+k};
0062 end;
0063 cur_a{d1} = tt_a{d1*p}(:,:,phys_j(p));
0064
0065 if (p==q)
0066 cur_a = tt_Fd_mtx1(cur_a, bound1, bound2,eps);
0067 else
0068 cur_a = tt_diag_av1(cur_a, eps);
0069 end;
0070
0071 M{d1*(p-1)+1}(1:2,1:2,1,1:size(cur_a{1},3)) = reshape(cur_a{1}, 2, 2, 1, size(cur_a{1},3));
0072 for k=2:d1-1
0073 M{d1*(p-1)+k}(1:2,1:2,1:size(cur_a{k},3),1:size(cur_a{k},4))=cur_a{k};
0074 end;
0075 M{d1*p}(1:2,1:2,1:size(cur_a{d1},3), 1) = reshape(cur_a{d1}, 2, 2, size(cur_a{d1},3), 1);
0076 end;
0077
0078 cur_a{1} = permute(tt_a{d1*(d_phys-1)+1}(:,phys_j(d_phys-1),:), [1 3 2]);
0079 for k=2:d1-1
0080 cur_a{k}=tt_a{d1*(d_phys-1)+k};
0081 end;
0082 cur_a{d1} = tt_a{d1*d_phys}(:,:,1);
0083
0084 if (q==d_phys)
0085 cur_a = tt_Fd_mtx1(cur_a, bound1, bound2,eps);
0086 else
0087 cur_a = tt_diag_av1(cur_a, eps);
0088 end;
0089
0090 M{d1*(d_phys-1)+1}(1:2,1:2,1,1:size(cur_a{1},3)) = reshape(cur_a{1}, 2, 2, 1, size(cur_a{1},3));
0091 for k=2:d1-1
0092 M{d1*(d_phys-1)+k}(1:2,1:2,1:size(cur_a{k},3),1:size(cur_a{k},4))=cur_a{k};
0093 end;
0094 M{d1*d_phys}(1:2,1:2,1:size(cur_a{d1},3), 1) = reshape(cur_a{d1}, 2, 2, size(cur_a{d1},3), 1);
0095
0096 if (first_comp==1)
0097 ttm = M;
0098 first_comp=0;
0099 else
0100 ttm = ttm_add(ttm, M);
0101 ttm = tt_mat_compr(ttm, eps);
0102 end;
0103 end;
0104
0105 phys_j(1)=phys_j(1)+1;
0106 for i=1:d_phys-2
0107 if (phys_j(i)>phys_ranks(i))
0108 phys_j(i)=1;
0109 phys_j(i+1)=phys_j(i+1)+1;
0110 end;
0111 end;
0112 end;
0113
0114 end