summation operation for a matrix?

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.

 Respuesta aceptada

Voss
Voss el 4 de Abr. de 2022
x = (1:36)+(1:36).' % some 36-by-36 matrix
x = 36×36
2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
% add first row and first column (exlcuding first element)
sum(x(1,:))+sum(x(2:end,1))
ans = 1402
% 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)
ans = 1402

3 comentarios

Azime Beyza Ari
Azime Beyza Ari el 4 de Abr. de 2022
thank you for your answer!
Yes it does what i want. But there is my fault by not explanin clearly. It should do it for the first index but it should also do it for other 35 index. How can i do that?
Torsten
Torsten el 4 de Abr. de 2022
Editada: Torsten el 4 de Abr. de 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:
There is no simpler way to do so.
You can have a look here for a simple example:
Azime Beyza Ari
Azime Beyza Ari el 4 de Abr. de 2022
Yes, i tried that but since my objective function only uses 1296 variable adding y's to Z caused too much error. Instead i wanted to eliminte y and work on x's. Since the whole idea behind y's are being equal to x's summation.

Iniciar sesión para comentar.

Más respuestas (0)

Productos

Versión

R2021b

Preguntada:

el 4 de Abr. de 2022

Comentada:

el 4 de Abr. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by