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

please help with Matlab on Problem 11: (8 points) In the following problem, x is

ID: 3665012 • Letter: P

Question


please help with Matlab

on Problem 11: (8 points) In the following problem, x is a vector containing the x-coordinates of 21 poimts The vector y contains the corresponding y-coordinates for the same 21 points. A vector pt 1ist contains a list of 10 point numbers to be visited consecutively. Write a Matlab function to calculate the total distance travelled moving through the points in the order given in pt list. The traverse starts at the first point and ends at the last point. You may use your distance function from Problem 9. IThe number 10 may be "hard-coded.") The first line is given below. function Id] - Total Distance lx, y,pt 11st)

Explanation / Answer

Vectorized implementation for computing the euclidean distance is significantly faster than PDIST2

D = sqrt( bsxfun(@plus,sum(A.^2,2),sum(B.^2,2)') - 2*(A*B') );

It is based on the fact that: ||u-v||^2 = ||u||^2 + ||v||^2 - 2*u.v

Matlab function to calculate total distance travelled moving through points is as:


total_dist = 0;
for i = 1:length(path)-1
total_dist = total_dist + distances(path(i),path(i+1));
end
total_dist = total_dist + distances(path(end),path(1));