How to make sigma from my problem using math lab code?
Show older comments
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 Comments
Rik
on 8 Oct 2020
This isn't your first question. Please format it properly.
Muhammad Sam'an
on 8 Oct 2020
Muhammad Sam'an
on 8 Oct 2020
Answers (1)
Walter Roberson
on 8 Oct 2020
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);
Categories
Find more on Arduino Hardware in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!