fitting 2d data set fit function is not working

조회 수: 2 (최근 30일)
Asliddin Komilov
Asliddin Komilov 2020년 3월 1일
댓글: Asliddin Komilov 2020년 3월 5일
Hi,
this is my data set and I wanted to try to get a fit for it.
well, did not work with
fit([x,y],z,'poly23');
first it said: Dimensions of matrices being concatenated are not consistent.
then I made x and y the same length and
it said: Y must be a column vector.
And now I am stack. help please.
thanks

채택된 답변

Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2020년 3월 1일
편집: Thiago Henrique Gomes Lobato 2020년 3월 3일
The problem is that your z data is defined in a grid while your x and y define only the vectors of this grid. If you first actually create the grid you will be able to create the model
[xmesh,ymesh] = meshgrid(x,y);
a = fit([xmesh(:),ymesh(:)],z(:),'poly23');
figure,surf(xmesh,ymesh,z),shading interp
hold on
plot3(xmesh(:),ymesh(:), a([xmesh(:),ymesh(:)]),'*' )
  댓글 수: 2
Asliddin Komilov
Asliddin Komilov 2020년 3월 2일
편집: Asliddin Komilov 2020년 3월 3일
thanks, meshgrid is new to me, I will do some reading.
what is the formula for the surface, why this one is not working:
axTc = a(1) + a(2) *x + a(3) *y + a(4) *x^2 + a(5) *x*y + a(6) *y^2 + a(7) *x^2*y + a(8) *x*y^2 + a(9) *y^3;
Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2020년 3월 3일
a is your linear model, but you can't acess the coefficients as a(x), but rather: a.p00, a.p01,etc... You can check the equation by looking at the output of the model
a
Linear model Poly23:
a(x,y) = p00 + p10*x + p01*y + p20*x^2 + p11*x*y + p02*y^2 + p21*x^2*y +
p12*x*y^2 + p03*y^3
Coefficients (with 95% confidence bounds):
p00 = 0.4365 (0.405, 0.4679)
p10 = 0.02601 (0.01672, 0.0353)
p01 = -0.0005043 (-0.0008066, -0.000202)
p20 = -0.09332 (-0.09619, -0.09046)
p11 = 0.0002262 (0.0001687, 0.0002837)
p02 = 1.986e-08 (-9.467e-07, 9.865e-07)
p21 = -7.72e-07 (-9.884e-06, 8.34e-06)
p12 = -2.696e-08 (-1.176e-07, 6.368e-08)
p03 = 8.97e-12 (-1.019e-09, 1.037e-09)
x and y must have the same length and you will need to use dot operators ( .*, .^) if you want to write the formula, although it is much easier to just give the x and y to your model as I did in the response.

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

추가 답변 (1개)

Asliddin Komilov
Asliddin Komilov 2020년 3월 4일
thanks, it is perfect but the fit gives this warning:
Warning: Equation is badly conditioned. Remove repeated data points or try centering and scaling.
does it influence the accuracy?
  댓글 수: 2
Thiago Henrique Gomes Lobato
Thiago Henrique Gomes Lobato 2020년 3월 4일
Sometimes yes, but in your case no. In your case you got an equation that basically perfect fits your curve.
Asliddin Komilov
Asliddin Komilov 2020년 3월 5일
thank you

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

카테고리

Help CenterFile Exchange에서 Get Started with Curve Fitting Toolbox에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by