Could you please do 1-5, in MATLAB code/software format please and thanks!! Obje
ID: 3699445 • Letter: C
Question
Could you please do 1-5, in MATLAB code/software format please and thanks!! Objective: Given a list of customer coordinates (r,, y) and the volume of material V to be distributed to those customers, find the location of a distribution center (a, b) that would minimize the total distribution costs plane with origin at (0,0), assume we have the following data for n Description: In a standard Elide customers: customer r (miles) y (miles Volume (tons/week) Vi 23 ?? /a The total delivery cost depends on the volume to be delivered V and the distance a customer from the distribution center. Assuming the distribution center is at coordinates (a, b), we will just use the Euclidean distance formula for the distance d, to reach each customer The cost ci for customeri can be approximated by d, V The distribution center will be placed somewhere at integer coordinates (a, b) with 0 a30 nd 0b 50 The goal is to create a function that accepts input vectors and y and V containing the data in the above columns of the table, and outputs the location values a and b representing the best location for the distribution center, that is, the one that minimizes the TOTAL cost for delivering to all customers. Directions: Download the template function file named delivery.m and add your name and date in the first two lines of comments on the indicated lnes. Fil in the code to accomplish the objectives below. Inside the function file you will also see two local functions. Create the local functions first, then call them inside your main function whenever needed as a way to simplify your code. Your main function file MUST satisfy the following 1. The name of the main function should be 'delivery' and have the form: function [a,b] = delivery (x,y,V) 2. It should accept three inputs, x, y, and V. The first input will be a row vector with of the r-coordinates for the locations of each customer. The second input will be a row vector with all of the y-coordinates for the locations of each customer. The third input will be a row vector V containing the weekly volumes requested by each customr Your function should should produce two outputs a and b, which are the best coordinates for the distribution center as described above 3. Start by completing the local function function [d]dist (X, Y,A,B) to return the distance d from the point (X,Y) to the point (A, B( scalar values) 4. Next complete the local function function [C] totalCost(x,y,V,A,B) to return the total cost C of delivering to all customers, if the distribution center was at location A, B 5. Finally, use two nested for loops in your main function to calculate the total cost of delivery for every possible A, B in the ranges allowed. Output as a and b the values that have the smallest costExplanation / Answer
matlab script for dist(X,Y,A,B):--
function [d]=dist(X,Y,A,B)
d=sqrt((A-X).^2+(B-Y).^2); %distance between points (X,Y) and (A,B)
end
matlab script for totalCost(x,y,V,A,B):--
function [C]=totalCost(x,y,V,A,B)
length=size(x); %find length for x
for k=1:length(2) %for every point given point (x(k),y(k))
distance=dist(x(k),y(k),A,B); %calculate distance from point (A,B)
cost(k)=distance*V(k)/2; %calculate cost to point (x(k),y(k)) from distribution center at (A,B)
end
C=sum(cost); %calculate total cost from distribution center at (A,B)
end
matlab script for delivery(x,y,V):--
function [a,b]=delivery(x,y,V)
oldcost=inf;
for i=0:1:30 %for eavery position in the intervel 0<=i<=30
for j=0:1:50 %for eavery position in the intervel 0<=j<=50
newcost=totalCost(x,y,V,i,j); %cost for distribution from the point (i,j)
if newcost<oldcost %if cost if lessthan previous cost
a=i; %assign new a as i for new x position
b=j; %assign new b as j for new y position
oldcost=newcost; %assign newcost to oldcost for next compare
end
end
end
end
output:--
x=[1 18 3 20 15 30];
>> y=[1 20 3 45 25 30];
>> v=[100 200 150 50 60 90];
>> [a,b]=delivery(x,y,v)
a =
18
b =
20
>>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.