Question: MATLAB PROBLEM 1 OF 5 Define a function named maxDistToCenter that takes 2 arguments as input: a single point, called the center, and a list

MATLAB

PROBLEM 1 OF 5

  1. Define a function named maxDistToCenter that takes 2 arguments as input: a single point, called the center, and a list of other points. The first line of the function should look like:

    function result = maxDistToCenter(center, other_pts)

    You may assume that center is a 1 2 vector containing the x- and y-coordinates of the center point and that other_pts is a N 2 matrix containing the x- and y-coordinates of N points, one point on each row.

    The function should return the maximum distance between the center and the other points. For example,

    Note: you will want to use MATLAB's max function; however, you will need to write the code that uses the distance formula to calculate the distance (MATLAB has a distance function, but it does not do what we want for this problem).

    • maxDistToCenter([1, 2], [1, 2]) should return 0 (the maximum distance between (1, 2) and (1, 2) )
    • maxDistToCenter([0, 0], [3, 4]) should return 5 (the maximum distance between (0, 0) and (3, 4) )
    • maxDistToCenter([0, 0], [1, 3; 2, 2; 3, 1]) should return the decimal approximation of the square root of 10, i.e., 3.162277660168380 (the maximum distance between (0, 0) and (1, 3), (2, 2), and (3, 1) )
  2. Demonstrate that your function works by adding code to your main homework script to call your function with the given center and other points. Display the results in the following format:

    Maximum distance to ( X , Y ) is N

    where X, Y, and N are replaced with the appropriate values. In order to receive full credit for this problem, you must must make appropriate use of the disp and num2str commands.

    center other points
    1. (1, 1) (8, 3)
    2. (3, 3) (0, 1), (2, 3), (4, 5), (6, 7), (8, 9)
    3. (7, 5) (0, 1), (2, 3), (4, 5), (6, 7), (8, 9)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!