  function ShowEllipsoid()
% Checks out Closest2E for finding the nearest point on an ellipsoid E
% to a given point p.

% Generate the thtree  semiaxes so that the largest is 1...
abc = rand(3,1); abc = abc/max(abc); a = abc(1); b = abc(2); c = abc(3);

% Note: (x/a)^2 + (y/b)^2 + (z/c)^2 = 1 is an "unrotated" ellipsoid E0 centered
% at the origin. We'll call E0 a "canonical" ellipsoid.

% Generate a random point on the sphere with center (0,0,0) and radius 10
p0 = randn(3,1); p0 = 10*p0/norm(p0);

% Note that p0 is outside of E0.

% Generate a random rotation and a random center..
[Q,R] = qr(randn(3,3));
r = 20*randn(3,1);

% Rotate and translate...
p = Q*p0 + r
E = struct('a',a,'b',b,'c',c,'r',r,'Q',Q);

% Note that p is outside of E. We mention that our method for generating
% a test problem results in a "nice" problem meaning that the prescribed
% steepest descent framework works (almost always!).

clc
itMax = 1000; 
tol = .001;
xStar = Closest2E(E,p,tol,itMax);
% To build confidence in your solution, you might want to display
% phi, theta, sqrt(fc), norm(gc), and tc after each iteration.

fprintf('\n\na = %8.4f\nb = %8.4f\nc = %8.4f\n\n\n\n',a,b,c)
fprintf('Q = [ %8.4f  %8.4f  %8.4f\n      %8.4f  %8.4f  %8.4f\n      %8.4f  %8.4f  %8.4f ]\n\n',Q)
fprintf('r     = [ %8.4f  %8.4f  %8.4f ]\n\n',r)
fprintf('p     = [ %8.4f  %8.4f  %8.4f ]\n\n',p)
fprintf('xStar = [ %8.4f  %8.4f  %8.4f ]\n\n',xStar)
        




  
