How can i sum my objective function with each iteration

1 visualización (últimos 30 días)
Azime Beyza Ari
Azime Beyza Ari el 22 de Mzo. de 2022
Comentada: Matt J el 22 de Mzo. de 2022
Hello everyone,
I am trying to do an maximiztion with optimization toolbox using genetic algorithm solver. What i am trying to do is i have a function with 2 parameters and 1 variable. I have a for loop and in the loop i wanna do this.
for i = 1:1
for j = 1:1296
z = z + (-1)*(xij(36*i+j-36)*aii(i,j)*r(i,j));
end
end
I wanna multpily the x,r, and a for each iteration and sum every iteration.
like this;
for (1,1)
x(1,1)*r(1,1)*a(1,1) = 188
for (1,2)
x(1,2)*r(1,2)*a(1,2)=74 +188= 262 (you get the idea)
Any suggestions on how to do this?
Because when i write it this was i get an error.
z = z + (-1)*(xij(36*i+j-36)*aii(i,j)*r(i,j));
Thank you in advance,
Beyza.

Respuesta aceptada

Matt J
Matt J el 22 de Mzo. de 2022
sum(x.*r.*a,'all')
  16 comentarios
Matt J
Matt J el 22 de Mzo. de 2022
You're welcome. If the problem is now resolved, though, please do Accept-click the answer.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Solver Outputs and Iterative Display en Help Center y File Exchange.

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by