function [Q,R]=QR(A)

[n,p]=size(A);
Q=A;
R=eye(n,n);
for i=1:n
		for j=1:i-1
		   M=eye(n,n);
			  M(j,i)=(Q(:,j)')*Q(:,i);
				Q(:,i)=Q(:,i)-M(j,i)*Q(:,j);
				 R=M*R;
		end;
		R(i,:)=R(i,:)*norm(Q(:,i));
		Q(:,i)=Q(:,i)/norm(Q(:,i));
end;
Q=Q;R=R;

endfunction;

//------------------------------------------
function B=inverse(A)

[n,p]=size(A);
Q=A;
Rinv=eye(n,n);
for i=1:n
		for j=1:i-1
		   Minv=eye(n,n);
			  Minv(j,i)=-(Q(:,j)')*Q(:,i);
				Q(:,i)=Q(:,i)+Minv(j,i)*Q(:,j);
				Rinv=Rinv*Minv;
		end;
		Rinv(:,i)=Rinv(:,i)/norm(Q(:,i));
		Q(:,i)=Q(:,i)/norm(Q(:,i));
end;

B=Rinv*(Q');

endfunction;

//---------------------------------------
function y=Jacobi(A,b,iter)

Minv=diag((1)./diag(A));
N=A-diag(diag(A));
P=Minv*N;
y=Minv*b;
for i=1:iter
		y=-P*y+Minv*b;
end;

endfunction;
