AUTH's THMMY "Parallel and distributed systems" course assignments.
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1234567891011121314151617181920212223
  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