%************************************************************
%        regls.m by www.boundary-element-method.com         *
% ***********************************************************
% Matlab/Freemat/Octave codes
% gls.m Version 1, June 2015
% http://www.researchgate.net/profile/Stephen_Kirkup
% School of Computing, Engineering and Physical Sciences
%  University of Central Lancashire
% Issued under the GNU General Public License 2007, see 
%  gpl.txt
%
% Source of the code: 
%  http://www.boundary-element-method.com/mfiles/gls.m
% Source of the user-guide: 
%  http://www.boundary-element-method.com/mfiles/gls_m.pdf
% Test code: 
%  http://www.boundary-element-method.com/mfiles/gls_t.m


function [x,y]=regls(n, xory, L, U, B_gls, perm, alpha, beta, c_new, f_new)
Tiny=0.000001;

c_int=c_new+B_gls*f_new;

x_int=LUfbsub(L, U, n, perm, c_int);
y_int=x_int;


% Complete the solution
for i = 1:n
  if xory(i) 
      y_int(i) = (f_new(i) - alpha(i) * x_int(i)) / beta(i);
  else
      x_int(i) = (f_new(i) - beta(i) * y_int(i)) / alpha(i);
  end
end

x=x_int;
y=y_int;


