MathGroup Archive 2001

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Fitting an ellipse

  • To: mathgroup at
  • Subject: [mg28125] Re: [mg28086] Fitting an ellipse
  • From: Tomas Garza <tgarza01 at>
  • Date: Sat, 31 Mar 2001 02:58:56 -0500 (EST)
  • References: <>
  • Sender: owner-wri-mathgroup at

Mathematica, by all means! Yes, suppose you want to fit the ellipse

x^2/a^2 + y^2/b^2 - 1 == 0

so that the two axes are parallel to the coordinate axes (no problem to
generalize it).
Say you have observed points {x, y}in a list called "points" {{x1,
y1},...,{xn, yn}}. Then transpose "points" to obtain a list of x's followed
by a list of y's:

{xes, yes} = Transpose[points];


Plus@@((x^2/a^2 + y^2/b^2 - 1)^2 /. {x -> xes, y -> yes});

gives you the sum of squares when you substitute each observed point into
the equation of the ellipse. In order to obtain the values of a and b that
minimize the sum of squares, just take the derivatives with respect to a and
b, equal them to zero, and solve. The whole thing can be reduced to a single
line of code:

Solve[(D[Plus (@@ (x^2/a^2 + y^2/b^2 - 1)^2 /.
         {x -> xes, y -> yes}), #1] == 0 & ) /@ {a, b},{a,b}]

and this will give you four solutions. Any of them will do, since a and b
enter only as squares in the equation of the ellipse.

Tomas Garza
Mexico City

----- Original Message -----
From: "Luisa Arruda" <luisa at>
To: mathgroup at
Subject: [mg28125] [mg28086] Fitting an ellipse

> I have x-y data that I need to fit an ellipse. Is it possible to construct
> a Fortran program or can I use mathematica or matlab to solve the problem?
> Thanks in advance for your attention,
> Luisa Arruda
> --------------------------------------------------------------------------
> "And as imagination bodies forth
>  The form of things unknown, the poet's pen
>  Turns them to shapes, and gives to airy nothing
>  A local habitation and a name."
>   Shakespeare
> luisa at
> luisa_arruda at
> df23432 at
> --------------------------------------------------------------------------

  • Prev by Date: Re: pde's
  • Next by Date: Re: What is happening here? (TagSet)
  • Previous by thread: Fitting an ellipse
  • Next by thread: Re: Fitting an ellipse