% Data reconciliation
% min S(x) = (y1 – x1)^2 + (y2 – x2)^2 + (y5 – x5)^2 + (y6 – x6)^2
%  s.a. h1(x) = x1 – x2 – x5 = 0
%		h2(x) = x2 + x5 – x6 = 0
%       x >= 0

i=[1; 2; 5; 6];
y = [101.91; 64.45; 34.65; 64.20; 36.44; 98.88];
Q=eye(4,4)*2
c=-y(i)*2
Aeq=[1 -1 -1 0; 0 1 1 -1]
beq=[0; 0]
lb=[0; 0; 0; 0]
ub=[]

op=optimset('LargeScale','off');
[xq,s,ex,out,lambda]=quadprog(Q,c,[],[],Aeq,beq,lb,ub,[],op)
x(i,1)=xq;
x(3)=x(5);
x(4)=x(2)
