function B = lsq_array_compute_rhs(X, F, W)

%Assumes that {X} is an array with {nt} rows (observations) and {nv} columns
%(independent variables), and {F} is a matrix with {nt} 
%rows and {nf == 1} columns (values of the dependent variables). Assumes 
%that {W(k,1)} is wheight of observation {k}.
%Returns an array {B} with {nv} rows and {nf} columns,
%contaning the right-hand-side of the linear system for the weighted 
%least squares problem with {nv} independent variables, {nt} observations, 
%and {nf} dependent variables).
%See {lsq_array_fit}. for details.

%Namely, sets {B} to {X'*diag(W)*F}; that is, set {B[i*nf+j]} to
%{SUM{ W[k]*X[k*nx+i]*F[k*nf+j] : k \in 0..nt-1 }} for all {i} in {0..nx-1}
%and all {j} in {0..nf-1}.


nt = size(X,1);
nx = size(X,2);
assert(size(W,1) == nt)
assert(size(W,2) == 1)
nf = size(F,2);
assert(size(F,1) == nt)

B = X'*diag(W)*F;
