求教Mathematica拟合隐函数椭圆方程问题(补充码)
mathematica吧
全部回复
仅看楼主
level 1
colopt 楼主
椭圆由方程Ax^2+Bxy+Cy^2+Dx+Ey+F=0表示,其中A、B、C、D、E、F为拟合参数,x、y为变量。现在有一系列的{x,y}数据,想要拟合得到A~F的参数值。但是给出的拟合结果是A~F六个参数全部为0,当然这是可以理解的,因为六个参数全部为0时,等式确实成立。想请教如何能够避免该问题,得到非0的参数值。非常感谢!!!
码如下:
dataraw={{0.42867,0.29316},{0.47231,0.52341},{0.48339,0.4966},{0.34955,0.2727},{0.48025,0.34219},{0.24471,0.43896},{0.25033,0.48827},{0.40938,0.28984},{0.49642,0.45106},{0.43251,0.55954},{0.34588,0.5664},{0.27422,0.32186},{0.2725,0.35105},{0.47521,0.33895},{0.41837,0.55882},{0.35466,0.57093},{0.4879,0.49352},{0.40899,0.29149},{0.25589,0.33504},{0.2597,0.35743},{0.43128,0.29059},{0.27037,0.47792},{0.40481,0.274},{0.25079,0.43302},{0.25335,0.35232},{0.38475,0.57225},{0.39276,0.28701},{0.49691,0.39056},{0.39209,0.27929},{0.4263,0.5599},{0.42127,0.27557},{0.28463,0.51501},{0.49577,0.42361},{0.29729,0.30011},{0.49573,0.47756},{0.47646,0.51795},{0.32093,0.5567},{0.43953,0.55303},{0.47472,0.50352},{0.45833,0.30911},{0.25645,0.43254},{0.28422,0.51962},{0.2634,0.51431},{0.49901,0.4231},{0.23357,0.44264},{0.48326,0.35592},{0.23996,0.44389},{0.29704,0.53519},{0.28227,0.51102},{0.27067,0.49698},{0.33554,0.27347},{0.41947,0.56016},{0.23213,0.41705},{0.25502,0.3416},{0.29413,0.5491},{0.37912,0.27493},{0.25152,0.45521},{0.30816,0.28566},{0.29243,0.30207},{0.38722,0.573},{0.32901,0.28196},{0.47873,0.50726},{0.23531,0.44914},{0.2353,0.40606},{0.49352,0.46001},{0.38458,0.56985},{0.47637,0.5083},{0.35976,0.26933},{0.40485,0.56567},{0.49548,0.38141},{0.41039,0.29039},{0.42901,0.30339},{0.45509,0.31613},{0.24907,0.39946},{0.25489,0.43712},{0.3154,0.28807},{0.42415,0.28183},{0.24795,0.39934},{0.3441,0.27762},{0.44443,0.54751},{0.36023,0.57168},{0.36901,0.58005},{0.34992,0.56988},{0.44218,0.54659},{0.32205,0.28402},{0.38432,0.27235},{0.26589,0.3527},{0.4038,0.28042},{0.36034,0.56435},{0.46004,0.32954},{0.47672,0.51373},{0.42796,0.5588},{0.49415,0.46632},{0.29093,0.30224},{0.4193,0.27234},{0.39982,0.27218},{0.27294,0.50896},{0.35982,0.27621},{0.342,0.28235},{0.39972,0.28645}};
datanumber=Length[dataraw];
data=Table[0,{datanumber},{3}];
Do[data[[i,1]]=dataraw[[i,1]];
data[[i,2]]=dataraw[[i,2]];
data[[i,3]]=0;
,{i,1,datanumber}];
a=.;
b=.;
c=.;
d=.;
e=.;
f=.;
xyfit=NonlinearModelFit[data,a*x^2+b*x*y+c*y^2+d*x+e*y+f,{a,b,c,d,e,f},{x,y}];
errortable=xyfit["ParameterTable"]
2019年12月10日 05点12分 1
吧务
level 12
直接令a=1就可以了
xyfit = NonlinearModelFit[data,
1*x^2 + b*x*y + c*y^2 + d*x + e*y + f, {b, c, d, e, f}, {x, y}];
errortable = xyfit["ParameterTable"]
ContourPlot[
xyfit[x, y] == 0, {x, Sequence @@ MinMax[dataraw[[All, 1]]]}, {y,
Sequence @@ MinMax[dataraw[[All, 2]]]},
Epilog -> {Red, PointSize[Large], Point[dataraw]}]
2019年12月10日 10点12分 2
嗯,是的,承蒙指教!!~非常感谢!~!!!
2019年12月11日 03点12分
1