can not get the answer

Could anyone help me with this problem? I can not get the same answer with the book. It should be =147.2551. This is I got so far
V=[3 7 4 5 2 6];
x=[1 7 8 17 22 27];
y=[28 18 16 2 10 8];
for i=1:30;
for j=1:30;
for k=1:6;
d(k)= sqrt((x(k)-i).^2+(y(k)-j).^2);
cost(k)=.5.*d(k).*V(k);
c(i,j)=sum(cost(k));
f=min(c(i,j));
end
end
end

 采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2012-10-12
编辑:Azzi Abdelmalek 2012-10-12
V=[3 7 4 5 2 6];
x=[1 7 8 17 22 27];
y=[28 18 16 2 10 8];
for i=1:30
for j=1:30
c(i,j)=0; % modification 1
for k=1:6
d(k)= sqrt((x(k)-i).^2+(y(k)-j).^2);
cost(k)=.5.*d(k).*V(k);
c(i,j)=c(i,j)+cost(k); %modification 2
end
end
end
f=min(c(:)) % modification 3

6 个评论

i did the last command
f=min(c(i,j)) the answer is 351.8830
f=min(c) the answer is array
My friend did like this compute each V, x, y, then get cost, then A(i,j)=cost did 6 times like that with each V, x,y then the end total_costweekly = min(min(A+B+C+D+E+F)) total_costweekly =147.2551 I don't want to do that way. too long, I use k=1:6 but i can not get the answer, help please
no, use
f=min(c(:))
the result
f =
147.2551
Thank you . You are the best. Oh god , It took me few days already!!!!!!!
I have 1 more problem. The program works but take several minutes to run, and give me a bunch, not 1 answer. Do you have the other way to make it precise? Thank you. Here is my program u=[80 50 40]; a=[1 1 0; 1 0 0; 2 2 1; 1 1 0; 2 2 1]; max_profit=0 another=[] f=[]
for p1=0:5:250 for p2=0:5:300 for p3=0:5:600 p=[p1,p2,p3]; if a*p' <=[450; 250; 800; 450; 600] profit=u*p'; else profit=0; end if profit > max_profit max_profit = profit; production = [p1,p2,p3]; elseif (max_profit - profit)<=1 another=[another;p]; f=[f, profit]; end end end end [m,n]=size(another); if m>1 disp(m-1) disp(another(2:m,:)) disp(f(2:m)') else disp('one solution') end
dzu format your code (look at Walter's link)

请先登录,再进行评论。

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Simulink 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by