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

3 commentaires

min(c(i,j)=c(i,j)
sss dzu
sss dzu le 12 Oct 2012
You did the same thing i did, not work
Walter Roberson
Walter Roberson le 13 Oct 2012
Please read the guide to tags and retag this question; see http://www.mathworks.co.uk/matlabcentral/answers/43073-a-guide-to-tags

Connectez-vous pour commenter.

 Réponse acceptée

Azzi Abdelmalek
Azzi Abdelmalek le 12 Oct 2012
Modifié(e) : Azzi Abdelmalek le 12 Oct 2012

0 votes

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 commentaires

sss dzu
sss dzu le 12 Oct 2012
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
Azzi Abdelmalek
Azzi Abdelmalek le 12 Oct 2012
Modifié(e) : Azzi Abdelmalek le 12 Oct 2012
no, use
f=min(c(:))
the result
f =
147.2551
sss dzu
sss dzu le 13 Oct 2012
Thank you . You are the best. Oh god , It took me few days already!!!!!!!
sss dzu
sss dzu le 13 Oct 2012
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
Azzi Abdelmalek
Azzi Abdelmalek le 13 Oct 2012
dzu format your code (look at Walter's link)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by