1
$\begingroup$

Given that point $A(0,3)$ and point $P(3,\frac{3}{2})$ are respectively on the ellipse $C:\frac{x^{2}}{a^{2}}+\frac{y^{2}}{b^{2}}=1(a>b>0)$,

To find the equation of this ellipse.


Method One:

sol = First@
  Solve[{x^2/a^2 + y^2/b^2 == 1 /. {x -> 0, y -> 3}, 
    x^2/a^2 + y^2/b^2 == 1 /. {x -> 3, y -> 3/2}}, {a, b}, 
   Assumptions -> {a > 0, b > 0}]
x^2/a^2 + y^2/b^2 == 1 /. sol

enter image description here


Method Two:

sol = First@
  Solve[{x^2/a^2 + y^2/b^2 == 1 /. Thread[{x, y} -> {0 , 3}], 
    x^2/a^2 + y^2/b^2 == 1 /. Thread[{x, y} -> {3, 3/2}]}, {a, b}, 
   Assumptions -> {a > 0, b > 0}]
x^2/a^2 + y^2/b^2 == 1 /. sol

enter image description here


What are some more efficient and better methods to solve for the equation of an ellipse?

$\endgroup$

4 Answers 4

4
$\begingroup$

I don't know why "efficient" or "better" in this case. Sometimes they're put in to make the question appear more interesting and less closable.

Here is a cool solution. Don't know whether it's efficient or better.

First@GroebnerBasis[
      x^2/a^2 + y^2/b^2 == 
        1 /. { {eq_ :> eq}, {x -> 0, y -> 3}, {x -> 3, y -> 3/2}}
      , {x, y}, {a, b}] == 0 // (* since a certain form is desired... *)
   Simplify //
  DivideSides[#, Last[#]] & //
 Expand

(*  x^2/12 + y^2/9 == 1  *)

For efficiency, one should solve numerically, not symbolically. Here's a start. Maybe others can show there are more efficient ways. I'm going hiking. Cya.

coeff = Table[
   Block[{x, y}, {x, y} = p; {x^2, y^2, -1}], {p, {{0, 3}, {3, 3/2}}}];
Thread[{a, b} -> 1/Sqrt[Most[#]/Last[#] &@ First@NullSpace@coeff]]

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

Shorter form of OP's entirely adequate solution:

Last@Solve[
  x^2/a^2 + y^2/b^2 == 1 /. 
   {{x -> 0, y -> 3}, {x -> 3, y -> 3/2}}, {a, b}]

(*  {a -> 2 Sqrt[3], b -> 3}  *)
$\endgroup$
1
  • $\begingroup$ Wonderful variety: enjoy the hike +1:) $\endgroup$
    – ubpdqn
    Commented Jul 10 at 20:30
2
$\begingroup$

I prefer to use smaller commands, one after the other. It is more clear and reduces the chance of making errors.

eq = x^2/a^2 + y^2/b^2 == 1
pts = {{0, 3}, {3, 3/2}}

And now

eqs = Map[eq /. {x -> #[[1]], y -> #[[2]]} &, pts]
sol = Solve[eqs, {a, b}, Assumptions -> {a > 0, b > 0}]

Plug the solution back into the equation

eq /. sol 

enter image description here

Ofcourse, since this is Mathematica, there are at least 10 different ways to code this. So just pick one style that is clear to you.

This is much more important than worrying about few nano seconds of efficiency.

$\endgroup$
1
  • $\begingroup$ Of course, since we're working with Mathematica, there are at least 10 different ways to approach coding a solution. So, just choose a style that makes sense to you and is clear. This is much more important than worrying about a few nanoseconds of efficiency. Writing code from different perspectives can help me become more familiar with the relationships between function statements, much like solving a problem with multiple methods. This is also a way to learn Mathematica effectively. $\endgroup$
    – csn899
    Commented Jul 10 at 13:24
2
$\begingroup$

Just a variant:

f[{x_, y_}] := {x, y} . DiagonalMatrix[{u, v}] . {x, y}
p = {{0, 3}, {3, 3/2}};
sol = Solve[Thread[f /@ p == 1], {u, v}][[1]];
ellipse = f[{x, y}] == 1 /. sol
{a, b} = {1/Sqrt[u], 1/Sqrt[v]} /. sol
foci = {Sqrt[a^2 - b^2], 0}
d = Norm[foci - #] + Norm[-foci - #] & /@ p // FullSimplify
ContourPlot[ellipse, {x, -4, 4}, {y, -4, 4}, 
 Epilog -> {Red, Point[p], Black, Point[{foci, -foci}], Purple, 
   Line[{{foci, #}, {-foci, #}}] & /@ p}, Axes -> True]

enter image description here

$\endgroup$
1
$\begingroup$
Clear[f]
f[x_, y_] := x^2/a^2 + y^2/b^2 == 1
sol = First@
  Solve[f @@@ {{0, 3}, {3, 3/2}}, {a, b}, 
   Assumptions -> {a > 0, b > 0}]
x^2/a^2 + y^2/b^2 == 1 /. sol

enter image description here


Thanks to Nasser's tips, the code can be made more concise.

Clear[f]
f[x_, y_] := x^2/a^2 + y^2/b^2 == 1
sol = First@
  Solve[f @@@ {{0, 3}, {3, 3/2}}, {a, b}, 
   Assumptions -> {a > 0, b > 0}]
f[x, y] /. sol

enter image description here

$\endgroup$
2
  • $\begingroup$ fyi, in your last line x^2/a^2 + y^2/b^2 == 1 /. sol can be replaced by f[x, y] /. sol. No need to copy/paste something you have already written above. Duplication can lead to errors. $\endgroup$
    – Nasser
    Commented Jul 10 at 13:05
  • $\begingroup$ @Nasser Written in response to your answers and by reviewing the usage of functions and the @@@ operator from my previous questions. Thank you! $\endgroup$
    – csn899
    Commented Jul 10 at 13:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.