MathGroup Archive 2001

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

Search the Archive

MATLAB to Mathematica 4.1

  • To: mathgroup at smc.vnet.net
  • Subject: [mg30694] MATLAB to Mathematica 4.1
  • From: Moranresearch at aol.com
  • Date: Sat, 8 Sep 2001 02:22:47 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

Could someone please help translate this six line of MATLAB code into Mathematica? I would like to use this method to fit ellipses to experimental data. 
Source code for the algorithm is supplied and a beautiful demonstration is available on http://vision.dai.ed.ac.uk/maurizp/ElliFitDemo/demo.htmlThank you. John R Moran PhD, MD

% x,y are list of coordinates
function a = fit_ellipse(x,y)

% Build design matrix
D = [x.*x x.*y y.*y x y ones(size(x))];

% Build scatter matrix
S = D'*D;

% Build 6x6 constarint matrix
C(6,6) = 0; C(1,3) = 2; C(2,2) = -1; C(3,1) = 2;

% Solve eigensystem
[gevec,geval] = eig(inv(S)**C);

% Find positive eigenvalue
[PosR,PosC] = find(geval > 0 & ~ isinf(geval));

% Extract eigenvector corresponding to positive eigenvalue
a = gevec(:,PosC);

Source code for the algorithm is supplied and a beautiful demonstration is available on http://vision.dai.ed.ac.uk/maurizp/ElliFitDemo/demo.html 








  • Prev by Date: Re: newbie: all possible sums of two lists
  • Next by Date: Extract coefs. and exponents from a list . Package problem
  • Previous by thread: Re: newbie: computing rational numbers and decimal
  • Next by thread: Re: MATLAB to Mathematica 4.1