looping a code efficiently
Afficher commentaires plus anciens
Hi,
I am writing a loop code for a particle. The equations involved are the following:
f_1x(t) = x_1;
v_1 = w*v_1 + c_p*rand*(x_1best - x_1) + c_n*rand*(g_best - x_1);
x_1 = x_1 + v_1;
As you can see, if I add another particle, all I need to do is actually add another set of those equations, and change all 1's to 2's. They will work out to be fine.
The problem is … if I want work with 100 other particles, there is should be a better way than just copying and pasting these equations 100 times!
Please help me find out what functions/commands I need for this. You do not need to write down the code for me. I need to know what commands/functions I should be dealing with so that I can study these after.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Loops and Conditional Statements 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!