AUTH's THMMY "Parallel and distributed systems" course assignments.
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 
 
 

24 rindas
536 B

  1. function [D2] = dist2(X, Y)
  2. % Calculates the squares of the distances of X and Y
  3. %
  4. % X: A Mxd array with m d-dimentional points
  5. % Y: A Nxd array with n d-dimentional points
  6. % d: Must be the same
  7. %
  8. % D2: The MxN matrix with the distances
  9. %
  10. [~, d1] = size(X);
  11. [~, d2] = size(Y);
  12. if d1 ~= d2
  13. error('X,Y column dimensions must match');
  14. end
  15. % debug
  16. %X_norm = sum(X.^2, 2);
  17. %Y_norm = sum(Y.^2, 2)';
  18. %XY = 2 * X*Y';
  19. D2 = max(sum(X.^2, 2) - 2 * X*Y' + sum(Y.^2, 2)', 0);
  20. D2 = sqrt(D2);
  21. end