% EG2p7.m Example 2.7 Heath
% The condition number of an ill-conditioned matrix A..
% K. Ming Leung, 02/13/05

clear all; hold off; format short e;
A = [0.913 0.659; 0.457 0.330]; 
%r=sqrt(3); A = 0.5*[r 1; -1 r]; 
d = det(A),
num = 2*(A(1,1)*A(1,2)+A(2,1)*A(2,2)),
den = A(1,1)^2+A(2,1)^2-A(1,2)^2-A(2,2)^2,
t = num/den, at = atan(t);
angle1 = 0.5*at; angle2= angle1+pi/2;

Theta = eps:0.01:2*pi; Theta2 = 2*Theta;
Cos = cos(Theta); Sin = sin(Theta);
Xpt = A(1,1)*Cos+A(1,2)*Sin;
Ypt = A(2,1)*Cos+A(2,2)*Sin;

subplot(1,2,1);
plot(Xpt,Ypt); axis('equal'); hold on;
plot([0 cos(angle1)],[0 sin(angle1)],'r');
plot([0 cos(angle2)],[0 sin(angle2)],'r');
plot([0 1],[0 1],'g');



subplot(1,2,2);
Fcn = 0.5*(sum(A(:).^2)+num*sin(Theta2)+den*cos(Theta2));
plot(Theta,num*cos(Theta2)-den*sin(Theta2),Theta,Fcn);


% A is ill-conditioned, it has a large condition number:
conditionA = cond(A,2),
