with A a (n,m) matrix, x and B are vectors of n-elements and a covariance matrix V ((n,n)matrix associated to B).
I found the following example to do so with uncorrelated error but not with an non diagonal covariance matrix V.
I believe this has already been solve using Minuit in :
Both the LinearFitter but also the standard Least square fitting in ROOT assume un-correlated errors. If you want to fit correlated data points, you would need to either use the direct solution as above in case of a linear problem, or write a general least square function with the data correlation matrix and then minimise using Minuit
////////////////////////////////////////////////////////////////////////////////
/// Solve min {(A . x - b)^T W (A . x - b)} for vector x where
/// A : (m x n) matrix, m >= n
/// b : (m) vector
/// x : (n) vector
/// W : (m x m) weight matrix with W(i,j) = 1/std(i)^2 for i == j
/// = 0 for i != j
TVectorD NormalEqn(const TMatrixD &A,const TVectorD &b,const TVectorD &std)
{
if (!AreCompatible(b,std)) {
::Error("NormalEqn","vectors b and std are not compatible");
return TVectorD();
}
TMatrixD mAw = A;
TVectorD mBw = b;
for (Int_t irow = 0; irow < A.GetNrows(); irow++) {
TMatrixDRow(mAw,irow) *= 1/std(irow);
mBw(irow) /= std(irow);
}
TDecompChol ch(TMatrixDSym(TMatrixDSym::kAtA,mAw));
Bool_t ok;
return ch.Solve(TMatrixD(TMatrixD::kTransposed,mAw)*mBw,ok);
}
Here a diagonal matrix is assumed but trivially replaced by a matrix.
The tutorial solveLinear.C might also give some inspiration:
Thank you for your answer.
I did look at the tutorial and at this function and I did try to replace the standard deviation by the full covariance matrix but the problem was not trivial for me as it involves a square-root of matrix .