MathGroup Archive 2001

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

Search the Archive

Re: Fitting an ellipse

  • To: mathgroup at smc.vnet.net
  • Subject: [mg28125] Re: [mg28086] Fitting an ellipse
  • From: Tomas Garza <tgarza01 at prodigy.net.mx>
  • Date: Sat, 31 Mar 2001 02:58:56 -0500 (EST)
  • References: <200103300912.EAA09808@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

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];

Then

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 lip.pt>
To: mathgroup at smc.vnet.net
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 lip.pt
> luisa_arruda at hotmail.com
> df23432 at einstein.cc.fc.ul.pt
> --------------------------------------------------------------------------
-----
>
>



  • 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