% Brad Nelson
% 2/25/12
% M126 HW 7 #1
% numerical rank of interaction

%-----------------------part a/b---------------------%

%n=[2:2:100 110:10:300]; %number of source/target points to try
n=logspace(0,3,50); %number of source/target points to try
rnks=zeros(size(n));

for i=1:numel(n);

src=rand(n(i),1)-0.5+1i*(rand(n(i),1)-0.5); %column vector of source points 

targ=rand(n(i),1)+1.5+1i*(rand(n(i),1)-0.5); %column vector of target points

[xx,yy]=meshgrid(src,targ); %sets up grid of points to evaluate

ker=-(1/(2*pi))*log(abs(xx-yy)); %kernel matrix

rnks(i)=rank(ker); %rank of kernel matrix

end

figure; %plots rank vs. n
semilogx(n,rnks,'.-');
axis([0 max(n) 0 max(rnks)+1]);
xlabel('n');
ylabel('rank');
print -depsc 1b.eps;


%-----------------------part c---------------------%
n=100;

src=rand(n,1)-0.5+1i*(rand(n,1)-0.5); %column vector of source points 

targ=rand(n,1)+1.5+1i*(rand(n,1)-0.5); %column vector of target points

[xx,yy]=meshgrid(src,targ); %sets up grid of points to evaluate

ker=-(1/(2*pi))*log(abs(xx-yy)); %kernel matrix

rank(ker,1e-10); %rank with tolerance of 1x10^-10
