function [x_r,mu]=reduktion_n(B,A,d,b)
% riesenie min 1/2 *x'Bx-d'*x s ohraniceniami danymi rovnicami
% A*x=b  ; B=nxn ,A=mxn; Z- nulovy podpriestor dany A*Z=0 , Y+Z=R^n z QR
% matice; x_r=Y*wy+Z*wz
[r,s]=size(A);g=s-r;

Z=null(A,'r'); Y=null(Z','g');
M1=Z'*B*Z; M2=A*Y;
wy=M2\b;
b1=Z'*d-Z'*B*Y*wy;
wz=M1\b1;
x_r=Y*wy+Z*wz;
b2=Y'*(d-B*x_r);
mu=M2'\b2;
