function Y=bgth(P,u,v,B)
%
%	This programm solve the linear matrix equation
%	AX=B, where A is an M-matrix expressed in the form
%	A=(P,u,v) - P: P=-A; 
%	            u,v > 0: Au=v; 
%

m=size(P);
n=m(1);
for k=1:1:n-1;
   alpha(k)=(v(k)+P(k,k+1:n)*u(k+1:n))/u(k);
   v(k+1:n)=v(k+1:n)+v(k)*P(k+1:n,k)/alpha(k);
   P(k+1:n,k+1:n)=P(k+1:n,k+1:n)+P(k+1:n,k)*P(k,k+1:n)/alpha(k);
end
alpha(n)=v(n)/u(n);
B(1,:)=B(1,:)/alpha(1);
for k=2:1:n,
   B(k,:)=(B(k,:)+P(k,1:k-1)*B(1:k-1,:))/alpha(k);
end
for k=n-1:-1:1;
   B(k,:)=B(k,:)+P(k,k+1:n)*B(k+1:n,:)/alpha(k);
end
Y=B;
