Azzera filtri
Azzera filtri

How can i sum my objective function with each iteration

2 visualizzazioni (ultimi 30 giorni)
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.

Risposta accettata

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

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by