How to make sigma from my problem using math lab code?
조회 수: 17 (최근 30일)
이전 댓글 표시
I want to calculate eval (x (pop_size)) = sigma (c (i, j) * x (i, j)) where i = 1 to m and j = 1 to n and I also want to calculate F = sigma ( eval (x (pop_size))) with pop-size = 1 up to pop_size = 25 with the following mathlab code
op_size = 5;
%sigma=0
%q=0
for count = 1:pop_size
%fprintf('count =%d\n',count);
c = [10 2 20 11
12 7 9 20
4 14 16 18];
[m,n] = size(c);
phi = 1:m*n;
s = [15
25
10
];
d = [5 15 15 15];
for count2=1:length(phi)
% fprintf('count2=%d\n',count2);
used_idx = randi(length(phi));
trial = phi(used_idx);
phi(used_idx) = [];
i = [1+mod((trial-1),m)];
j = [1+mod((trial-1),n)];
x(i,j) = min(s(i),d(j));
s(i) = s(i)-x(i,j);
d(j) = d(j)-x(i,j);
Eval=0;
for j=1:n
for i=1:m
if x(i,j)>0
Eval=Eval+c(i,j)*x(i,j);
%fprintf('Eval=%d\n',Eval);
end
end
end
end
disp(Eval)
end
i use the sum function but the result is not what i want ...
댓글 수: 4
답변 (1개)
Walter Roberson
2020년 10월 8일
op_size = 5;
%sigma=0
%q=0
all_Evals = zeros(pop_size,1);
for count = 1:pop_size
%fprintf('count =%d\n',count);
c = [10 2 20 11
12 7 9 20
4 14 16 18];
[m,n] = size(c);
phi = 1:m*n;
s = [15
25
10
];
d = [5 15 15 15];
for count2=1:length(phi)
% fprintf('count2=%d\n',count2);
used_idx = randi(length(phi));
trial = phi(used_idx);
phi(used_idx) = [];
i = [1+mod((trial-1),m)];
j = [1+mod((trial-1),n)];
x(i,j) = min(s(i),d(j));
s(i) = s(i)-x(i,j);
d(j) = d(j)-x(i,j);
Eval=0;
for j=1:n
for i=1:m
if x(i,j)>0
Eval=Eval+c(i,j)*x(i,j);
%fprintf('Eval=%d\n',Eval);
end
end
end
end
disp(Eval)
all_Evals(count) = Eval;
end
sum_of_Evals = sum(all_Evals);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Arduino Hardware에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!