Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I get leastsquares fit?

I got an error when I try to use CNiMath::LeastSquaresFit(). Please teach me what I was wrong.

The error message is "Math Exception:Input matrix is singular. The system of equation cannot be solved."

I donot thick my matrix is singular. The program code is as follows:

CNiReal64Matrix HMat(3,2);

HMat(0,0) = 1.0;
HMat(0,1) = 2.0;
HMat(1,0) = 5.0;
HMat(1,1) = 4.0;
HMat(2,0) = 5.0;
HMat(2,1) = 3.0;

CNiReal64Vector YVec(3);
YVec[0] = 5.0;
YVec[1] = 6.0;
YVec[2] = 7.0;

CNiReal64Vector stdDev(3);
stdDev.Set(0.0);

CNiReal64Vector BVec(2), ZVec(3);
CNiReal64Matrix Covari(3,3);

double mse;

CNiMath::LeastSquaresFit(HMat,YVec,stdDev,ZVec,BVec, Covari,mse);

Please check it. Thank you.
0 Kudos
Message 1 of 2
(3,140 Views)
The documentation in previous versions of Measurement Studio incorrectly said to set the stdDev vector to all zeroes to disregard standard deviations in the computation. Doing this causes the computation to fail in most cases. If you set all elements in the stdDev vector to the same non-zero value (1.0 for instance), then your fit will work. The standard deviation value will not affect the outcome of your computation so long as it is the same for all elements.

Let me know if you have any further problems.

Tony H.
Message 2 of 2
(3,140 Views)