clear all; 
close all;
rand('state')
global c;
n=5
q=rand(n,2);
c=1;
m=70
p=rand(m,2);
am=matgen(p,q);
rhs=zeros(2*m,1);
rx=rand(1,1);
ry=rand(1,1);
for i=1:m
    km=kermatgauss(p(i,1)-rx,p(i,2)-ry,c)+0.2*(1-2*rand(2,2));
    rhs(2*i-1:2*i,1)=km(:,2);
end
% rhs =rand(2*m,1);
% conda=condest(am)
co=am\rhs;
h=0.05;
[xe ye]=meshgrid(0:h:1,0:h:1);
xxe=xe(:);
yye=ye(:);
em=matgen([xxe yye],q)*co;
emx=em(1:2:end);
emy=em(2:2:end);
quiver(xxe,yye,emx,emy)
hold on
quiver(p(:,1),p(:,2),rhs(1:2:end),rhs(2:2:end),'r')
axis([-0.2 1.2 -0.2 1.2])
% title(sprintf('Interpolation to noisy vector field in %d locations',m))
return
figure(2)
surf(xe,ye,reshape(emx,size(xe)))
hold on
plot3(p(:,1),p(:,2),rhs(1:2:end),'*')
figure(3)
surf(xe,ye,reshape(emy,size(xe)))
hold on
plot3(p(:,1),p(:,2),rhs(2:2:end),'*')
return
