问题:用椭圆拟合数据 {{13, 60}, {36, 35}, {70, 29}, {106, 41}, {118, 72}, {94,
94}, {49, 99}, {24, 85}}
解法:
data = {{13, 60}, {36, 35}, {70, 29}, {106, 41}, {118, 72}, {94,
94}, {49, 99}, {24, 85}};
data0 = PadRight[#, 3] & /@ data;
ellipse = (x - x0)^2/a^2 + (y + y0)^2/b^2 - 1 /.
Thread[{x, y} -> RotationTransform[u][{x, y}]];
cond = FindFit[data0, ellipse, {x0, y0, a, b, u}, {x, y}];
ContourPlot[Evaluate[ellipse == 0 /. cond], {x, 0, 120}, {y, 0, 120},
AspectRatio -> Automatic, Epilog -> {Point /@ data}]
94}, {49, 99}, {24, 85}}
解法:
data = {{13, 60}, {36, 35}, {70, 29}, {106, 41}, {118, 72}, {94,
94}, {49, 99}, {24, 85}};
data0 = PadRight[#, 3] & /@ data;
ellipse = (x - x0)^2/a^2 + (y + y0)^2/b^2 - 1 /.
Thread[{x, y} -> RotationTransform[u][{x, y}]];
cond = FindFit[data0, ellipse, {x0, y0, a, b, u}, {x, y}];
ContourPlot[Evaluate[ellipse == 0 /. cond], {x, 0, 120}, {y, 0, 120},
AspectRatio -> Automatic, Epilog -> {Point /@ data}]