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

The solution should give me nxn Matrix that show distances between city 1,2,...,

ID: 3694516 • Letter: T

Question

The solution should give me nxn Matrix that show distances between city 1,2,...,n and city 1,2,....,n . It should get points as input argument function [distances]=distanceCalculater(points) something like that. Excel File Edit View Insert Format Tools Data Window Help 4) Workbook 1 Home Layout Tables Charts SmartArt Data Review Aignment Bad Good Merge G13 04482 0,8225 20,8018 09364 3 0,7444 0,5538 4 3948 0,6962 ,38880,0801 093660,3639 0,0000 0,3715 0,4000 0,1371 0,7448 0,6699 0,6194 0,3277 0,3419 0,3396 0,3715 0,0000 0,3869 0,4726 0,9507 0,5881 0,9328 0,5890 0,6964 0,7103 0,4000 0,3869 0,0000 0,3776 0,5923 0,2701 0,6712 0,3398 0,7078 0,6576 4 0,1371 0,4726 0,3776 0,0000 0,6162 0,6356 0,4842 0,1996 0,3322 0,2832 0,7448 0,9507 0,5923 0,6162 0,0000 0,6169 0,3391 0,4176 0,8339 0,7225 6 0,6699 0,5881 0,2701 0,6356 0,6169 0,0000 0,8141 0,5437 0,9678 0,9061 0,6194 0,9328 0,6712 0,4842 0,3391 0,8141 0,0000 0,3492 0,5720 0,4556 0,3277 0,5890 0,3398 0,1996 0,4176 0,5437 0,3492 0,0000 0,4754 0,3865 0,3419 0,6964 0,7078 0,3322 0,8339 0,9678 0,5720 0,4754 0,0000 0,1165 00,3396 0,7103 0,6576 0,2832 0,7225 0,9061 0,4556 0,3865 0,1165 0,0000 1 2 0748 0907 091 06152 0.6169 00000 08141 0.54370,9678 0,901 70.1255 0,2938 8 0,4094 0,4971 9 0,1090 0,8656 10 0,1165 0,7493 3 0 Microsoft Excel 26

Explanation / Answer

function distances = distanceCalculater(points)
    distances = zeros(length(points),length(points))
    for i = 1: length(points)
        p1 = points{i}
        for j = 1: length(points)
           p2 = points{j}
           if( i != j)
               distances(i,j) = sqrt( (p1(1)-p2(1)) * (p1(1)-p2(1)) + (p1(2)-p2(2)) * (p1(2)-p2(2)))
           end
       end
   end
  
  

end

points = { [0 0] [0 5] [4 0] [5 6] [8 9]}
disp(distanceCalculater(points))

---------output--------------

                                                                                                                           

    0.00000    5.00000    4.00000    7.81025   12.04159                                                                    

    5.00000    0.00000    6.40312    5.09902    8.94427                                                                    

    4.00000    6.40312    0.00000    6.08276    9.84886                                                                    

    7.81025    5.09902    6.08276    0.00000    4.24264                                                                    

   12.04159    8.94427    9.84886    4.24264    0.00000                                                                    

sh-4.3$