function A = lsq_array_compute_matrix(X, W)
%Assumes that {X} is matrix where {X(k,j)} is the observed value of
%variable {j} in measurement {k}, for {j} in {1:nx} and {k} in {1:nt}.
%Assumes that {W(k,1)} is the weight of measurement {k}. 
%Returns the linear system matrix {A} ({nx x nx}) for the weighted least squares
%problem with those measurements and weights.
%See {lsq_array_fit}. for details.
 
%Namely, sets {A} tp {X'*diag(W)*X} where {X} denotes matrix trasposition; 
%that is, sets {A(i,j)} to {SUM{ W(k,1)*X(k,i)*X(k,j) : k \in 1..nt}}
% for all {i,j} in {1..nx}. 

nt = size(X,1);
nv = size(X,2);
assert(size(W,1) == nt)
assert(size(W,2) == 1)
A = X'*diag(W)*X;
