function [x_r]=reduktion(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 , Ap_r=b partikularne riesenie
%x_r=p_r+Z*q_r, Z'BZq_r=-(Z'*B*p_r-Z'*d);X=Z+Y
[r,s]=size(A);
p_r=A\b;
if r==s
    x_r=p_r;Z=zeros(r,1);q_r=p_r;
else
Z=null(A,'r')
bb=-(Z'*B*p_r-Z'*d);
BR=Z'*B*Z;
q_r=BR\bb;
x_r=p_r+Z*q_r
end
