function target

% ellipse containing possible solutions to Ax=b
% kappa(A)>>1 for d close to 1

d = 1.00000001

% pick solution and matrix
x=[1;1];
A=zeros(2,2);
A(1,1)=1;
A(1,2)=1;
A(2,1)=d;
A(2,2)=1;

kappa=cond(A,inf)
Ai=inv(A);
b=A*x;

% generate both circle and ellipse
nt=400;
th=linspace(0,2*pi,nt);
for it=1:nt
    u(it)=cos(th(it))+b(1);
    v(it)=sin(th(it))+b(2);
    x1(it)=Ai(1,1)*u(it)+Ai(1,2)*v(it);
    y1(it)=Ai(2,1)*u(it)+Ai(2,2)*v(it);
    dist(it)=sqrt((x1(it)-x(1))^2+(y1(it)-x(2))^2);
end
md=max(dist);
N=round(md);

clf
% get(gcf)
set(gcf,'Position', [1 909 905 436])

% draw circle
subplot(1,2,1)
hold on
plot(u,v,'--r','LineWidth',2.5)
plot(b(1),b(2),'.r','MarkerSize',50)
axis([b(1)-1 b(1)+1 b(2)-1 b(2)+1])
set(gca,'XTick',[b(1)-1 b(1) b(1)+1])
set(gca,'XTickLabel',{'b(1)-2eps';'b(1)';'b(1)+2eps'})
set(gca,'YTick',[b(2)-1 b(2) b(2)+1])
set(gca,'YTickLabel',{'b(2)-2eps';'b(2)';'b(2)+2eps'})
axis equal
box on
grid on
xlabel('b-vector')
say=['\kappa = ', num2str(round(kappa))];
text(b(1)-0.25,b(2)-0.5,say,'FontSize',20,'FontWeight','bold')
set(gca,'FontSize',16,'FontWeight','bold')

% draw ellipse
subplot(1,2,2)
hold on
plot(x1,y1,'LineWidth',1.6)
axis([x(1)-md x(1)+md x(2)-md x(2)+md])
set(gca,'XTick',[x(1)-md x(1) x(1)+md])
set(gca,'XTickLabel',{'x-N*eps';'x';'x+N*eps'})
set(gca,'YTick',[x(2)-md x(2) x(2)+md])
set(gca,'YTickLabel',{'y-N*eps';'y';'y+N*eps'})
axis equal
box on
grid on
xlabel('x_c')
say=['N = ', num2str(N)];
text(x(1)-0.3*md,x(2)-0.8*md,say,'FontSize',20,'FontWeight','bold')
set(gca,'FontSize',16,'FontWeight','bold')

















