0

Here is the assignment i need help with. i have attached the assignment and the main code and function file are below.

thanks

MAIN CODE

clear all

clc

min_d=fminsearch(@distance, [0,30]);

v=[3,7,4,5,2,6];

for i=1:6

if i==1;

c1=.5 * min_d * v(i);

end

if i==2;

c2=.5 * min_d * v(i);

end

if i==3;

c3=.5 * min_d * v(i);

end

if i==4;

c4=.5 * min_d * v(i);

end

if i==5;

c5=.5 * min_d * v(i);

end

if i==6;

c6=.5 * min_d * v(i);

end

end

min_c=c1+c2+c3+c4+c5+c6;

fprintf('the minimum cost is 2.1%',min_c)


FUNCTION FILE

function d= distance(x2,y2)

x1=[1,7,8,17,22,27];

y1=[28,18,16,2,10,8];

d=sqrt((x2-x1)^2+(y2-y1)^2);

end

1
Contributor
1
Reply
2
Views
6 Years
Discussion Span
Last Post by unk45
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.