4

If the equation of ellipse is:

$$\frac{x^2}{a^2}+\frac{y^2}{b^2}=1,$$

then how can the major and minor axes values in the denominators be extracted from eq?

eq = x^2/4 + y^2/3 == 1;

a^2=4; a=2; b^2=3; b=sqrt(3)

Trunk
  • 103
  • 2
csn899
  • 3,953
  • 6
  • 13

5 Answers5

10

Expressing the ellipse as eq == 0:

eq = x^2/4 + y^2/3 - 1;

The semi-major axes are calculated from the eigenvalues of the second derivatives of eq:

1/Sqrt[Eigenvalues[D[eq, {{x, y}, 2}]/2]] // NumericalSort
(*    {Sqrt[3], 2}    *)

This is more general than pattern-matching approaches and also works on rotated ellipses:

eq = x^2/4 + x y/7 + y^2/3 - 1;
1/Sqrt[Eigenvalues[D[eq, {{x, y}, 2}]/2]] // NumericalSort
(*    {2 Sqrt[42/(49 + Sqrt[193])], 2 Sqrt[42/(49 - Sqrt[193])]}    *)
Roman
  • 47,322
  • 2
  • 55
  • 121
5
eq1 = x^2/4 + y^2/3 == 1;
eq2 = x^2/a^2 + y^2/b^2 == 1;
Solve[Denominator[Flatten@(List @@@ List @@ eq1)] == 
  Denominator[Flatten@(List @@@ List @@ eq2)], 
 Assumptions -> {a > 0 && b > 0}]

{{a -> 2, b -> Sqrt[3]}}

bmf
  • 15,157
  • 2
  • 26
  • 63
5

Another possibility is (*8 more left to do *)

ClearAll["Global`*"]
eq = x^2/4 + y^2/3 == 1;
normalized = First[eq] - Last[eq]

Mathematica graphics

Coefficient[normalized, x^Exponent[normalized, x]];
Sqrt[Denominator[%]]  (*a*)

Mathematica graphics

Coefficient[normalized, y^Exponent[normalized, y]];
Sqrt[Denominator[%]]  (*b*)

Mathematica graphics


If the exponent is not meant to be the max but only 2 then do

ClearAll["Global`*"]
eq = x^2/4 + y^2/3 == 1;
normalized = First[eq] - Last[eq]
Sqrt[Denominator[Coefficient[normalized, x^2]]] (*a*)
Sqrt[Denominator[Coefficient[normalized, y^2]]] (*b*)

Mathematica graphics

Nasser
  • 143,286
  • 11
  • 154
  • 359
5
eq = x^2/4 + y^2/3 == 1;
TreeForm[eq]

enter image description here

To extract the coefficients:

(1/Sqrt[#]) &@(First /@ Level[eq, {2}])

{2, Sqrt[3]}

Syed
  • 52,495
  • 4
  • 30
  • 85
4

try https://resources.wolframcloud.com/FunctionRepository/resources/EllipseProperties

ass = ResourceFunction["EllipseProperties"][x^2/4 + y^2/3 == 1, {x, y}];
ass["SemimajorAxisLength"]
ass["SemiminorAxisLength"]

2

Sqrt[3]

enter image description here

AsukaMinato
  • 9,758
  • 1
  • 14
  • 40