How to make sigma from my problem using math lab code?

17 ビュー (過去 30 日間)
Muhammad Sam'an
Muhammad Sam'an 2020 年 10 月 8 日
回答済み: Walter Roberson 2020 年 10 月 8 日
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 件のコメント
Rik
Rik 2020 年 10 月 8 日
Have a read here.
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 Center および File ExchangeArduino Hardware についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by