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

Please help me!!! The border is given in a file, but I dont know what to do next

ID: 3834846 • Letter: P

Question

Please help me!!!

The border is given in a file, but I dont know what to do next.

Cody coursework x Final 201757 D Finalproe updated pdr x Faceboo C Secure https//ttu blackboard com cswebdav pid-245808 content-rid-13890396 1 /courses 20175/-ME-2115-301/Final Project updated.pd Specifics of the problem 1. Create the USA border and I00 cities inside the border including a hub city a) Write a function M-file cities -m that creates the location of cities inside a given border. It has three inputs, N border and hub N is a positive integer bigger than 0, that presents the desired number citics to be created. The input variable border is a matrix of dimension nx2. Every row of border represents thexand y coordinates of points located along the border ofa polygon shape (with 3 ponts it is a triangular shape, with more it can be any irregular polygon shape in general. The input hub is a row vector (1x2) that gives the x and y coordinates of the hub city. The location of the hub city is stored as the first row of the N+1 2 output matrix P.Next randomly create N cities inside the border. Every city is resented by its x coordinate (a randomly generated real number in the range of coordinates of border) and its y coordinate (another randomly generated real number in the range ofy coordinates of border), such that it is located inside the polygon defined by borde (hint: use built-in function inpolygon to check ifa point is inside the polygon or not). The location of the i- th city is stored as the i-th row of the matrix. P Eunction cities .m: Inputs: N, a positive integer bigger than 0, border. an nx2 matrix hub, a 1x2 row vector Output: P an (N+1)x2 matrix, whose i-th row is (x,y coordinates) of the ith city Example border 0; 3 1; 6 5 2 4 1 1]; hub 9801 3.7846 P-cities 6, border, hub 9801 3.7846 1.3597 0.9067 2.8457 3.8510 4.5396 3.7019 2.4068 2.5281 3.6038 4611 9406 0.1811 a Type here to search 2:48 PM 5/6/20

Explanation / Answer

Given below is a MATLAB program for given problem. Descriptive comments are added within cities function at each step. Sample execution output is also provided for reference.

File: cities.m

function P = cities(N, border, hub)
% This function outputs an (N+1)x2 matrix P whose ith row
% is (X, Y) co-ordinates of the ith city

% Store location of hub city as the first row
P = [hub];

% Find range for city co-ordinates (X, Y) based on border polygon points
range = [min(border); max(border)];

% Initialize counter for cities generated
count = 1;

while( count < (N+1) )
% Generate city co-ordinates (X, Y) randomly
X=(range(2,1)-range(1,1))*rand(1,1)+range(1,1);
Y=(range(2,2)-range(1,2))*rand(1,1)+range(1,2);

% Check if city co-ordinates are located within border
IN = inpolygon(X,Y,border(:,1),border(:,2));
if IN(1,1) == 1
% City located within border
  
% Store location of city
P=[P; X Y;];
  
% Increment cities generated counter by one
count = count + 1;
end
end

Sample Execution Output:

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote