Skip to main content
17-Peridot
January 7, 2016
Solved

Least Squares Fit does not compute

  • January 7, 2016
  • 11 replies
  • 3699 views

Hello folks,

does anybody understand why this leastsquaresfit does not compute for this plain problem?

Thanks in advance

Raiko

p.S.

I'm using Mathcad 15 M045 on a Win 7 machine.

Best answer by RichardJ

It's a scaling problem. I would expect changing TOL or CTOL would fix it (this would work for genfit or minerr), but it seems that does not work.

Your guess value for the slope was also a long way off.

11 replies

RichardJ19-TanzaniteAnswer
19-Tanzanite
January 7, 2016

It's a scaling problem. I would expect changing TOL or CTOL would fix it (this would work for genfit or minerr), but it seems that does not work.

Your guess value for the slope was also a long way off.

Raiko17-PeridotAuthor
17-Peridot
January 7, 2016

Well yes, the guess values where indeed far off, however I've had success with even wilder guess values for linear problems.

Thanks

Raiko

19-Tanzanite
January 7, 2016

Yes, the guess value was not the fundamental problem. That was just an additional observation

25-Diamond I
January 7, 2016

Here's a possible way to automate the scaling and rescaling. It should also not be necessary to deal with "UntisOf" because "mean" would take care of the units.

Is there a better, shorter way to do the rescaling?

We have to multiply the whole 2 x 3 marix with mean(s.1) (which is easy to achieve) and then only the first row has to be divided by mean(e.1).

EDIT: I just notice that the rescaling of coeff needs a unit strip off, which should be easy to accomplish. The reason ist that we cannot have different dimensions in a matrix, which would be the case, if e.1 is not dimensionless.

Its interesting that "line", which also should use a least square fit, I guess, dies not show this scaling problem.

Regards, Werner

19-Tanzanite
January 7, 2016

Its interesting that "line", which also should use a least square fit, I guess, dies not show this scaling problem.

But it's a linear least squares fit, so there is no iterative process. It just does some matrix algebra.

minerr etc do suffer from similar scaling problems (although I have not tried this specific data set) because CTOL is an absolute number, not a relative one. So if your numbers are like these, around 10^8, a convergence tolerance of 10^-3 is one part in 10^11. It would be much better if the convergence criterion were relative, so 10^-3 meant that the chi-square changed by less than one part in 10^3.

25-Diamond I
January 8, 2016

Richard Jackson wrote:

Its interesting that "line", which also should use a least square fit, I guess, dies not show this scaling problem.

But it's a linear least squares fit, so there is no iterative process. It just does some matrix algebra.

Sure, of course you are right. Shame on me 😞

But what about genfit - which algorithm is used here?

Don't think that genfit "realises" that f is linear.

> It would be much better if the convergence criterion were relative

But relative to which value?

Its something I tried to achieve in the approach in my next post, but I can think of situations where this approach will fail, too.

25-Diamond I
January 7, 2016

Here is the modified sheet using an allpurpose, unit-aware LeastSquareFit routine which also should not show those scaling problems.

I just noticed that I never changed your original guess vector. It really seems not to matter that its way off.

Regards, Werner

Raiko17-PeridotAuthor
17-Peridot
January 8, 2016

Hello Werner,

neat function!

Raiko