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

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

댓글을 달려면 로그인하십시오.

 채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2012년 10월 12일
편집: Azzi Abdelmalek 2012년 10월 12일

0 개 추천

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

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

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Time Series Events에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by