The function cov2ellipse in the geometry package is not computing the ellipse axes correctly. The first problem is that the scale of the axes is wrong. This can be demonstrated with the code below

  ######################################################################
  function cov2ellipse_demo (K)
      L = chol(K,'lower');
      u = randn(1e3,2)*L';
      elli = cov2ellipse (K);
      figure(1)
      plot(u(:,1),u(:,2),'.r');
      hold on;
      drawEllipse(elli,'linewidth',2);
      hold off;
      axis tight;
  endfunction
  cov2ellipse_demo (K); ## This is what we get with "demo cov2ellipse"
  cov2ellipse_demo (10*K);
  cov2ellipse_demo (0.1*K);
  ######################################################################

This is fixed by taking the square root of the eigenvalues obtained by svd().

The second problem is that the axis orientation is wrong, evidenced in the code below:

  ######################################################################
  K = [2 -1; -1 2];
  cov2ellipse_demo (K)
  ######################################################################

This happens because the wrong elements of the eigenvectors are taken.

The patch attached below fixes both problems.

Rafael

Index: cov2ellipse.m
===================================================================
--- cov2ellipse.m	(revision 11451)
+++ cov2ellipse.m	(working copy)
@@ -53,8 +53,8 @@
     print_usage
   end
   [R S W] = svd (K);
-  theta = atan (R(1,1)/R(2,2));
-  v     = sort (diag(S), 'ascend')';
+  theta = atan2 (R(2,1), R(1,1));
+  v     = sqrt (diag(S))';
 
   if nargout == 1
     varargout{1} = [0 0 v theta*180/pi];
------------------------------------------------------------------------------
Monitor your physical, virtual and cloud infrastructure from a single
web console. Get in-depth insight into apps, servers, databases, vmware,
SAP, cloud infrastructure, etc. Download 30-day Free Trial.
Pricing starts from $795 for 25 servers or applications!
http://p.sf.net/sfu/zoho_dev2dev_nov
_______________________________________________
Octave-dev mailing list
Octave-dev@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/octave-dev

Reply via email to