# HELP: Why poly11 fit is not fitting my data?

2 views (last 30 days)
erik jensen on 8 May 2020
Commented: dpb on 17 May 2020
HELLO,
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];
f=fit([X,Y],Z,'poly11');
figure
plot(f,[X,Y],Z) 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)

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(3)=c(3)/std(Y);
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 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 on 17 May 2020
Furthermore:
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?