%matrix_hiba

a=1e-10;
A1=[1 a 0;1 0 a]; A2=[1 1;a 0;0 a]; A3=[-1 a 0;1 0 a]; A4=[-1 1;a 0;0 a];
Ap1=A1*A2*A3*A4, Ap2=A1*(A2*A3)*A4, Ap3=(A1*A2)*(A3*A4)

A1B=qdata(A1,'BFP'); A2B=qdata(A2,'BFP'); A1B=qdata(A3,'BFP'); A4B=qdata(A4,'BFP'); 
A1d=qdata(A1,'double'); A2d=qdata(A2,'double'); A3d=qdata(A3,'double'); A4d=qdata(A4,'double');
A1B, A1d
qclear %clear quantizers
qmake('Qd','double')
qset('Qd','operation','PQN')
qget('Qd')

Aprecise=qdata(A1,'BFP')*qdata(A2,'BFP')*qdata(A3,'BFP')*qdata(A4,'BFP')

for c=1:3
	varAdi=zeros(2,2);
	c
	for ii=1:20
		if c==1, Adi=qdata(A1,'Qd')*qdata(A2,'Qd')*qdata(A3,'Qd')*qdata(A4,'Qd');
		elseif c==2, Adi=qdata(A1,'Qd')*(qdata(A2,'Qd')*qdata(A3,'Qd'))*qdata(A4,'Qd');
		elseif c==3, Adi=(qdata(A1,'Qd')*qdata(A2,'Qd'))*(qdata(A3,'Qd')*qdata(A4,'Qd'));
		end
		varAdi=(ii-1)/ii*varAdi+1/ii*(double(Adi)-double(Aprecise)).^2;
	end
	format short e, Ap=double(Aprecise), Astd=sqrt(varAdi)
end