A greedy method to solve a linear system [SOL]=ALS_SOLVE2(MAT,RHS,EPS,[SOL],[NITER]) Computes approximate solution to the linear system MAT*SOL=RHS such as the residue is bounded by ||MAT*SOL-RHS||<EPS*||RHS|| or maximum number of iterations is achieved 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 [sol1]=als_solve2(mat,rhs,eps,sol,niter) 0002 %A greedy method to solve a linear system 0003 % [SOL]=ALS_SOLVE2(MAT,RHS,EPS,[SOL],[NITER]) Computes approximate 0004 % solution to the linear system MAT*SOL=RHS 0005 % such as the residue is bounded by ||MAT*SOL-RHS||<EPS*||RHS|| 0006 % or maximum number of iterations is achieved 0007 % 0008 % 0009 % TT-Toolbox 2.2, 2009-2012 0010 % 0011 %This is TT Toolbox, written by Ivan Oseledets et al. 0012 %Institute of Numerical Mathematics, Moscow, Russia 0013 %webpage: http://spring.inm.ras.ru/osel 0014 % 0015 %For all questions, bugs and suggestions please mail 0016 %ivan.oseledets@gmail.com 0017 %--------------------------- 0018 0019 0020 0021 if ( nargin < 4 || isempty(sol) ) 0022 sol=zeros(numel(rhs),1); 0023 end 0024 if ( nargin < 5 || isempty(niter) ) 0025 niter=1000; 0026 end 0027 %Magic parameters 0028 loc_slv=10; 0029 m0=tt_matrix(mat); 0030 nrm=norm(rhs); 0031 0032 rhs1=rhs-m0*sol; 0033 if ( norm ( rhs1 ) > norm (rhs ) ) 0034 sol1=zeros(size(sol)); 0035 rhs1=rhs; 0036 else 0037 sol1=sol; 0038 end 0039 i=1; 0040 er=2*eps*nrm; 0041 m=size(mat{2},1); 0042 while ( i < niter && er > eps*nrm ) 0043 0044 [x,y]=als_solve(mat,rhs1,randn(m,1),loc_slv); rhs1=rhs1-(m0*kron(y,x)); 0045 sol1=sol1+kron(y,x); 0046 er=norm(rhs1); 0047 fprintf('i=%d, er=%3.2e \n',i,er/nrm); 0048 %keyboard; 0049 i=i+1; 0050 0051 end 0052 0053 0054 return 0055 end