필터 지우기
필터 지우기

Calculating covariance matrix from Jacobian using lsqcurvefit

조회 수: 30 (최근 30일)
Wolfgang Klassen
Wolfgang Klassen 2019년 6월 4일
댓글: Alan Weiss 2020년 4월 29일
I am trying to calculate the covariance matrix from the residuals vector and the Jacobian matrix, which are optional outputs of the lsqcurvefit function. I keep getting negative values for the diagonal (variance) values, but they should be strictly positive. Does this have something to do with the method that lsqcurvefit uses? I have attached sample data and a sample extPar structure (this usually gets generated other peices of code that call this function). The part of the code that I think is germane is here:
[par,resnorm,R,~,~,~,J] = lsqcurvefit(FID,par0,fitTime,fitData);
pCov = inv(J'*J)*((R'*R)./(numel(fitData) - numel(par)));
The fit function converges to a nice looking solution, am I doing something drastically wrong here?
I am fully aware that the statistics toolbox solves this easily, but unless you give my prof the cash to buy it for me, I'm stuck with this.
  댓글 수: 1
David Wilson
David Wilson 2019년 6월 5일
편집: David Wilson 2019년 6월 5일
Your analysis looks reasonable. The matrix J'*J is positive definite by definition, and so is its inverse. R'*R will be positive and so is nu = n-m. However numerical ill-conditioning could be the problem. Check the eigenvalues of inv(J'*J), they should be all +ve (or zero). What is the condition # or rcond of J'*J ?
Of course there are square root methods (SVD etc) to do this that avoid the possible ill-conditioning.

댓글을 달려면 로그인하십시오.

채택된 답변

Alan Weiss
Alan Weiss 2019년 6월 6일
This old documentation example might be of some use.
Alan Weiss
MATLAB mathematical toolbox documentation
  댓글 수: 4
Samuel Grauer
Samuel Grauer 2020년 4월 29일
This documentation link appears to be broken. What was the solution?
Alan Weiss
Alan Weiss 2020년 4월 29일
The documentation link is now broken permanently. Sorry. I think that I am not supposed to post the information, which was removed from the doc purposefully.
Alan Weiss
MATLAB mathematical toolbox documentation

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Matt J
Matt J 2019년 6월 5일
편집: Matt J 2019년 6월 5일
J'*J is only guaranteed to be positive semi-definite, which means some of the diagonals can be zero in ideal math. However, computers do not perform ideal math. Due to numerical precision limitations, the calculation can have small inaccuracies and give you slighly negative values in diagonals that are supposed to be zero.

카테고리

Help CenterFile Exchange에서 Linear Algebra에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by