how to write the mathlab code for the sigma formula below?
Afficher commentaires plus anciens
suppose I have a value
Eval (X_1) = 40
Eval (X_2) = 30
Eval (X_3) = 70
Eval (X_4) = 80
Eval (X_5) = 24
Eval (X_6) = 35
Eval (X_7) = 86
Eval (X_8) = 74
Eval (X_9) = 63
Eval (X_10) = 52
F = sigma (Eval (X_ (h))) where h = 1 to h = 10
please help mathlab code for sigma F formula?
4 commentaires
Mario Malic
le 7 Oct 2020
John D'Errico
le 7 Oct 2020
Learn how to use vectors. Do not try to create numbered variables like this, as this is a programming style that will only bridge you programming pain.
Muhammad Sam'an
le 7 Oct 2020
Réponses (1)
Walter Roberson
le 7 Oct 2020
sum(Eval([X_1, X_2, X_3, X_4, X_5, X_6, X_7, X_8, X_9, X_10]))
this assumes that Eval is a vector, or that Eval is a function that is vectorized.
If Eval is a function that is not vectorized then
sum(arrayfun(@Eval, [X_1, X_2, X_3, X_4, X_5, X_6, X_7, X_8, X_9, X_10]))
4 commentaires
Muhammad Sam'an
le 7 Oct 2020
Muhammad Sam'an
le 7 Oct 2020
Modifié(e) : Muhammad Sam'an
le 8 Oct 2020
Steven Lord
le 8 Oct 2020
Initialize Eval to 0 before the for count = 1:pop_size statement. This will accumulate all the values added to it in the iterations over count, count2, j, and i.
Walter Roberson
le 8 Oct 2020
For whatever reason, the poster has a requirement that they use "sigma" (sum) for this purpose, so incremental addition is not an acceptable solution to them.
I posted exact code for them at https://www.mathworks.com/matlabcentral/answers/607961-how-to-make-sigma-from-my-problem-using-math-lab-code#answer_508396
Catégories
En savoir plus sur Variables dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!