%---- First part: construction of the vectors ----- % initialization for the different vectors denominator=d(1)+u(1)*v(1); a(1)=-v(1)/denominator; mu(1)=b(1)/denominator; f(1)=1; g(1)=1; % initialization for the different inner products ip=a(1)*v(1); % the inner product r^T y ipl=mu(1)*v(1); % the inner product r^T x % The main loop for i=2:n % initialize t=u(i)*ip+v(i); denominator=(u(i)*t+d(i)); % Calculation of alpha a(i)=-t/denominator; % Calculation of the factor f f(i)=(1+u(i)*a(i)); % The calculation of mu mu(i)=(b(i)-u(i)*ipl)/denominator; % The factor g g(i)=mu(i)*u(i); % the inner product r^T x ipl=ipl+mu(i)*t; % the inner product r^T y ip=a(i)*t+ip; end %---- Second part: construction of the solution ---- % we construct now the solution with the 4 vectors. x(n)=mu(n); factor=g(n); for i=n-1:-1:1 x(i)=mu(i)+factor*a(i); factor=g(i)+f(i)*factor; end
An easy calculation reveals that the complexity of this solver is
operations.