MATLAB Answers

HELP: Why poly11 fit is not fitting my data?

2 views (last 30 days)
erik jensen
erik jensen on 8 May 2020
Commented: dpb on 17 May 2020
Could you please help me?
I have fitted around 40 surfaces from points, with the same code , all off them fit properly except for this one:
X = [478590; 478430; 478370; 478260; 478210; 478370];
Y= [7429630.703; 7429513.568 ; 7429475.211; 7429388.671; 7429363.763; 7429477.185];
Z= [2302.848; 2221.125; 2250.860; 2196.164; 2270.641; 2119.579];
WHY??? If they are very close to a flat plane
What can I do?
I have tried almost all the fit options
(The objective is to fit them to a flat plane to evaluate " coplanarity" with Rsquare)

  1 Comment

dpb on 8 May 2020
You left out one important piece of information...
Warning: Equation is badly conditioned. Remove repeated data points or try centering and scaling.
> In curvefit.attention/Warning/throw (line 30)
In fit>iLinearFit (line 680)
In fit>iFit (line 391)
In fit (line 116)

Sign in to comment.

Answers (1)

dpb on 8 May 2020
Edited: dpb on 8 May 2020
>> zX=(X-mean(X))/std(X);
>> zY=(Y-mean(Y))/std(Y);
>> f=fit([zX,zY],Z,'poly11')
Linear model Poly11:
f(x,y) = p00 + p10*x + p01*y
Coefficients (with 95% confidence bounds):
p00 = 2227 (2124, 2330)
p10 = -78.27 (-2713, 2556)
p01 = 97.4 (-2537, 2732)
Following the suggestion helps significantly in this case.
The algebra is simple enough to transform back to original coefficients--
c=coeffvalues(f); % standardized model coefficients
C=c(1)-c(2)*mean(X)/std(X)-c(3)*mean(Y)/std(Y); % constant coefficient in X,Y
C(2)=c(2)/std(X); % X, Y coefficients
C =
-7298467.21 -0.58 1.02
>> [f(zX,zY) [ones(size(X)) X Y]*C.']
ans =
2258.28 2258.28
2232.28 2232.28
2228.21 2228.21
2204.21 2204.21
2208.01 2208.01
2230.23 2230.23
I have/had "format bank" on at the moment so only two decimal places shown, but are same to rounding precision, but far more stable estimate of the coefficients.


erik jensen
erik jensen on 17 May 2020
I really apreciate your effort to help me.
However, even normalizing de data I get the same bad correlation (and small R2) that does not reflect the real spatial distribution (see attached image)
erik jensen
erik jensen on 17 May 2020
Why did you suggest normalize only 2 dimensions? (X Y and not Z) -UPDATE: I normalized the 3 of them and got the same bad correlation-
In wich part of the suggesting code you are obtaining R2?
Many thanks for your help!
dpb on 17 May 2020
I overlooked that the bounds estimates for p10, p01 are still huge despite the warning going away.
Your data are simply so nearly collinear the model doesn't fit well...
I've got pressing deadline so not able to spend more time right now, sorry, but you could try removing the 3rd or last point which are identically collinear in X and see if that would remove enough to help.
After that would have to delve in deeper than have time for right now.
As for why X,Y not X, it's the independent variables that build the X estimator matrix; Y just shows up on RHS so doesn't really affect solution.

Sign in to comment.

Translated by