function [xs, ys] = f(mean, cov, steps)

% [xs, ys] = ellipse(mean, cov, steps)
%
% Compute an ellipse with center given by mean and shape given by the
% symmetric positive definite matrix cov.  The axes of the ellipse will
% point along the eigenvectors of cov, with lengths equal to the square
% roots of the corresponding eigenvalues.  So for example, to scale the
% ellipse uniformly by a factor of k, multiply cov by k^2.
%
% The optional parameter steps tells how many line segments to break
% the ellipse into.  The coordinates of the vertices are returned in xs
% and ys, with the last point a duplicate of the first.  So for
% example, to draw a red dotted ellipse, use
%   line(xs,ys,'Color',[1 0 0],'LineStyle',':')


if (nargin < 3)
  steps = 30;
end
step = 1/steps;
angles = pi * [-1+step:2*step:1];
angles = angles(:);

[v,d] = eig(full(cov));
points = [sin(angles) cos(angles)] * sqrt(d) * v';
points = [points; points(1,:)];
xs = points(:,1)+mean(1);
ys = points(:,2)+mean(2);
