Filter löschen
Filter löschen

How can i sum my objective function with each iteration

2 Ansichten (letzte 30 Tage)
Azime Beyza Ari
Azime Beyza Ari am 22 Mär. 2022
Kommentiert: Matt J am 22 Mär. 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.

Akzeptierte Antwort

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

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by