Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

5. Write a function euclid2(x,y) that computes the squared Euclidean distance be

ID: 3561852 • Letter: 5

Question

5. Write a function euclid2(x,y) that computes the squared Euclidean distance between two vectors of similar shape: d(Vector x, Vector y)=Sigma i=1 to N(xi-yi)^2 where N is the length of vectors x and y. Do not use a loop, this can be represented as matrix operations. Show the result of the distortion between the first pair of vectors of both features2 and features3. 6. Write function mindist that takes a column vector (Nxl) and a matrix with the same number of rows and an arbitrary number of columns (NxM). Compute the squared Euclidean distance between the vector and each column, then return the minimum distance and the index of the column that produced it. The min function can return both a minimum value and index from a vector and will be useful for this problem. The function mindist will be useful for developing a k -means algorithm.

Explanation / Answer

function euclid2(x,y)

c=(x-y).^2;

d=sum(c);

fprintf('distance: %0.2f',d);

end

---_------------------------------------------------------_-----_------

function mindist(col,mat)

s=size(mat);

d=zeros(1,s(2));

for i=1:s(2)

d(i)=sum((col-mat(:,i)).^2);

end

[m,n]=min(d);

fprintf('minimum distance: %0.2f. and column index: %d',m,n);

end

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote