Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions