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 个评论
Muhammad Sam'an
Muhammad Sam'an 2020-10-8
thank you ... I have fixed this ... can you give me a solution to my problem?

请先登录,再进行评论。

回答(1 个)

Walter Roberson
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);

类别

Help CenterFile Exchange 中查找有关 Arduino Hardware 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by