% Zadanie 3.5
y = [2.2 1.3 3.2 4.5]';
m = [6 20 30 6]'/1e2;


A = [ 1 -1 ; 2 0 ; 0 1 ; 2 1 ];
w = [2 -0.4 2.4 1.0]';

P =diag(m.^-1);

L = w - y;
X = -inv(A'*P*A)*(A'*P*L);
V = A*X+L;

sigma0 =  (V'*P*V)/(size(A,1)-size(A,2));

% Zadanie 3.6
y     = [4.5 -1.0 5.0 ]';
sigma = [1,2,3];

Cy = diag(sigma.^2);
Cy(3,1) = 1.2;
Cy(1,3) = Cy(3,1);

A = [ 1 0 ;  1 1 ; 2 0];
w = [4 -5 2 ]';
L = w -y;

P = inv(Cy);
X = -inv(A'*P*A)*(A'*P*L);
V = A*X+L;
sigma0 =  (V'*P*V)/(size(A,1)-size(A,2));


% Zadanie. 4.8

C = [ 2 1 0;
      1 3 1;
      0 1 2 ] ;

D = [ 1 1 1 ] ;

Cf = D * C * D';

mf = sqrt(diag(Cf)) ;

rho_yz = C(2,3)/sqrt(C(2,2)*C(3,3)) ;
