Effacer les filtres
Effacer les filtres

How can i sum my objective function with each iteration

3 vues (au cours des 30 derniers jours)
Azime Beyza Ari
Azime Beyza Ari le 22 Mar 2022
Commenté : Matt J le 22 Mar 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.

Réponse acceptée

Matt J
Matt J le 22 Mar 2022
sum(x.*r.*a,'all')
  16 commentaires
Azime Beyza Ari
Azime Beyza Ari le 22 Mar 2022
@Matt J okey thank you!
Matt J
Matt J le 22 Mar 2022
You're welcome. If the problem is now resolved, though, please do Accept-click the answer.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by