helsing.m 938 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. function A = helsing(n)
  2. %
  3. % A = helsing(n)
  4. %
  5. % This file creates a matrix A whose entries are defined by :
  6. % A(i,j)= -log|z(i)-z(j)| , if i .neq. j
  7. % -log|r(i)|
  8. % where z(i) are n somehow randomly distributed points in a unit square
  9. % centered at the origin in the complex plane and where each r(i) is a
  10. % number in (0,d(i)[, d(i) being the distance between the point z(i) and
  11. % its nearest neighbour.
  12. %
  13. % Input :
  14. % n : size of the matrix A
  15. % Output :
  16. % A : square matrix of size n as described above
  17. %
  18. % 07 February 13
  19. %
  20. xi=rand(n,1)*2-1;
  21. yi=rand(n,1)*2-1;
  22. [xj,yj]=meshgrid(xi,yi);
  23. xj=xj'-xj;
  24. yj=yj'-yj;
  25. coef=-1;
  26. for i=1:max(size(xj))
  27. d0=0;
  28. for j=1:n
  29. temp=sqrt((xi(i)-xi(j))^2+(yi(j)-yi(i))^2);
  30. if (temp>0)
  31. A(i,j)=coef*log(temp);
  32. if (d0==0)
  33. d0=j;
  34. A(i,i)=-log(0.5*d0*rand());
  35. end
  36. end
  37. end
  38. end