[Solved]-Question 2 25 Points Implement Following Functions Specified Function D Al Dist P Calculat Q37284408
using matlab,
Question 2: (25 points) Implement the following functions as specified. function D = al!Dist (P) % Calculate the distances between the cities in struct array P. % p: 1-d struct array of location data. Each struct in P has these 3 fields : % name: (char row vector) the name of a city % x: (type double scalar) x-coordinate of the city % y: (type double scalar) y-coordinate of the city % P contains data for distinct locations and the length of P is at least 2. % D: square mat % in P. The number of rows (and columns) of D is the length of array P. b(1.) is % the distance between locations i and j, which is equal to D(j,i) % Only these built-in functions are allowed: length, zeros, sqrt % For full credit, be efficient by avoiding unnecessary calculations . rix (type double) storing all pair-vise distances betveen the locations iength (P) D zeras (,n) end ond function V = furthestApart (P) % Determine the two locations that are furthest % P: 1-d struct array of location data as described above. % V: % If multiple pairs of cities are the same maximum distance apart, V is any one of apart given location data in P cell array storing the names of the tvo cities in P that are furthest apart Length 2 those pairs. % Make effective use of function allDist from Part (a) % Only these built-in functions are allowed: length, size, cell % For full credit, be efficient by avoiding unnecessary iterations Show transcribed image text Question 2: (25 points) Implement the following functions as specified. function D = al!Dist (P) % Calculate the distances between the cities in struct array P. % p: 1-d struct array of location data. Each struct in P has these 3 fields : % name: (char row vector) the name of a city % x: (type double scalar) x-coordinate of the city % y: (type double scalar) y-coordinate of the city % P contains data for distinct locations and the length of P is at least 2. % D: square mat % in P. The number of rows (and columns) of D is the length of array P. b(1.) is % the distance between locations i and j, which is equal to D(j,i) % Only these built-in functions are allowed: length, zeros, sqrt % For full credit, be efficient by avoiding unnecessary calculations . rix (type double) storing all pair-vise distances betveen the locations iength (P) D zeras (,n) end ond function V = furthestApart (P) % Determine the two locations that are furthest % P: 1-d struct array of location data as described above. % V: % If multiple pairs of cities are the same maximum distance apart, V is any one of apart given location data in P cell array storing the names of the tvo cities in P that are furthest apart Length 2 those pairs. % Make effective use of function allDist from Part (a) % Only these built-in functions are allowed: length, size, cell % For full credit, be efficient by avoiding unnecessary iterations
Expert Answer
Answer to Question 2: (25 points) Implement the following functions as specified. function D = al!Dist (P) % Calculate the distanc… . . .
OR

