i have this
q = {Off[NMinimize::eit]; Off[NMinimize::lstol];
DynamicModule[{rng, ptk, final},
Panel[Column[{"Theta z przedzia?u od 0 do:",
RadioButtonBar[
Dynamic[rng], {2 -> "2", Pi/8 -> "\[Pi]/8", Pi/2 -> "\[Pi]/2",
Pi -> "\[Pi]", 2 Pi -> "2\[Pi]"}],
"Ilo?? generowanych punktów:",
RadioButtonBar[
Dynamic[ptk], {5 -> "5", 20 -> "20", 50 -> "50",
100 -> "100"}],
Button["Generuj Elipse",
While[True,(*Randomly choose coefficients until \
acceptable*){a, b, c, d, f, g} = RandomReal[{-10, 10}, 6];
\[CapitalDelta] = -c d^2 + 2 b d f - a f^2 - b^2 g + a c g;
j = -b^2 + a c; i = a + c;
If[\[CapitalDelta] != 0 && j > 0 && \[CapitalDelta]/i < 0,
Break[]]];
ellipse = a*x^2 + 2*b*x*y + c*y^2 + 2*d*x + 2*f*y + g;
(*Center of an ellipse in general form is{(c d-b f)/(b^2-
a c),(a f-b d)/(b^2-a c)}*)
points = Table[theta = RandomReal[{0, rng}];
ksol = FindRoot[(ellipse /. {x ->
k*Cos[theta] + (c d - b f)/(b^2 - a c),
y -> k*Sin[theta] + (a f - b d)/(b^2 - a c)}) ==
0, {k, 1.}];
Point[{x, y}] /. {x ->
k*Cos[theta] + (c d - b f)/(b^2 - a c),
y -> k*Sin[theta] + (a f - b d)/(b^2 - a c)} /.
ksol, {ptk}];
nearpoints =
points /.
Point[{x_, y_}] :>
Point[{x + RandomReal[{-.1, .1}],
y + RandomReal[{-.1, .1}]}];
(*ellipse x and y min and max values*)
yplotrange =
Flatten[{y,
Sort[{(2*b*d - 2*a*f +
Sqrt[(2*b*d - 2*a*f)^2 -
4*(b^2 - a*c)*(d^2 - a*g)])/(2*(-b^2 + a*c)), (-2*b*
d + 2*a*f +
Sqrt[(2*b*d - 2*a*f)^2 -
4*(b^2 - a*c)*(d^2 - a*g)])/(2*(b^2 - a*c))}]}];
xplotrange =
Flatten[{x,
Sort[{(2*c*d - 2*b*f +
Sqrt[(-2*c*d + 2*b*f)^2 -
4*(b^2 - a*c)*(f^2 - c*g)])/(2*(b^2 - a*c)), (-2*c*
d + 2*b*f +
Sqrt[(-2*c*d + 2*b*f)^2 -
4*(b^2 - a*c)*(f^2 - c*g)])/(2*(-b^2 + a*c))}]}];
(*minimize distance of near points to a new general ellipse*)
nearCoords = nearpoints[[All, 1]];
{xs, ys} = Transpose[nearCoords];
newellipse = aa*x^2 + 2*bb*x*y + cc*y^2 + 2*dd*x + 2*ff*y + gg;
distance = Plus @@ (newellipse^2 /. {x -> xs, y -> ys});
{res, coes} = NMinimize[distance, {aa, bb, cc, dd, ff, gg}];
scaleup =
FromDigits[{{1}, Last@RealDigits[1/(gg /. coes)] + 1}];
esolve = Expand[scaleup*(newellipse /. coes)];
final =
Show[ContourPlot[{ellipse == 0, esolve == 0},
Evaluate[xplotrange], Evaluate[yplotrange],
ImageSize -> {200, Automatic}], Graphics[points],
Graphics[{Red, nearpoints}]];], Dynamic@final}]]]};
Grid[{{Labeled["(A)", q], Labeled["(B)", q]}, {Labeled["(C)", q],
Labeled["(D)", q]}}]
and i want add this to chose between n and m
m = {{res, coes} = NMinimize[distance, {aa, bb, cc, dd, ff, gg}];
scaleup = FromDigits[{{1}, Last@RealDigits[1/(gg /. coes)] + 1}];
esolve = Expand[scaleup*(newellipse /. coes)];};
n = {{res, coes} =
FindMinimum[{distance, -bb^2 + aa*cc >
0., (-cc*dd^2 + 2 bb*dd*ff - aa*ff^2 - bb^2*gg +
aa*cc*gg)/(aa + cc) < 0.}, {{aa, a}, {bb, b}, {cc, c}, {dd,
d}, {ff, f}, {gg, g}}];
esolve = newellipse /. coes;};
it's possible to add some menu to make it all work?