Is it possible to realize such loop in MATLAB?
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Good day, everyone!
For example, we have some x variable.
Is it possible to realize such loop (using "for") to get these results?
1-st iteration: x-1
2-nd iteration: (x-1)*(x-2)
3-rd iteration: (x-1)*(x-2)*(x-3)
etc.
0 Commenti
Risposta accettata
Voss
il 16 Set 2024
x = 10;
n_iterations = 5;
results = zeros(1,n_iterations);
r = 1;
for ii = 1:n_iterations
r = r*(x-ii);
results(ii) = r;
end
results
Or, without the loop:
results = cumprod(x-(1:n_iterations))
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!