summation operation for a matrix?
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Azime Beyza Ari
am 4 Apr. 2022
Kommentiert: Azime Beyza Ari
am 4 Apr. 2022
Hello everyone,
I have a matrix with dimensions 36x36. what i want to is this;
x(1,1)+x(1,2)+...+x(1,36) +x(2,1)+x(3,1)+x(4,1)+...+x(36,1) <= (somevalue)
I am using genetic algorithm solver. For another constraint i have, i did this;
con.sumrows=(sum(x,1)<=1);
Is there any simple solution for i want like above line? suggestions are welcomed.
Thank you in advance.
0 Kommentare
Akzeptierte Antwort
Voss
am 4 Apr. 2022
x = (1:36)+(1:36).' % some 36-by-36 matrix
% add first row and first column (exlcuding first element)
sum(x(1,:))+sum(x(2:end,1))
% or add first row and first column then subtract first element because it
% was included twice
sum(x(1,:))+sum(x(:,1))-x(1,1)
3 Kommentare
Torsten
am 4 Apr. 2022
Bearbeitet: Torsten
am 4 Apr. 2022
I have a matrix with dimensions 36x36. what i want to is this;
x(1,1)+x(1,2)+...+x(1,36) +x(2,1)+x(3,1)+x(4,1)+...+x(36,1) <= (somevalue)
You don't have this matrix.
You must construct the matrix which implements this constraint.
In the matrix I set up for the other constraint, just set the ones at the correct positions, and you'll get the above constraint implemented:
https://de.mathworks.com/matlabcentral/answers/1687409-dependent-variable-operations?s_tid=srchtitle
There is no simpler way to do so.
You can have a look here for a simple example:
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Genetic Algorithm finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!