Effacer les filtres
Effacer les filtres

For loop with previous result

1 vue (au cours des 30 derniers jours)
Jane Smith
Jane Smith le 5 Mar 2021
Commenté : Jane Smith le 5 Mar 2021
for t=1:n
a(t)=600+10^t
b(t)=600-a(t)
end
I want that b to always taking the previous result
so, b(1)=600-a(1)
b(2)=(600-a(1))-a(2)
b(3)=(600-a(1)-a(2))-a(3)
how can i change the t

Réponse acceptée

Mathieu NOE
Mathieu NOE le 5 Mar 2021
hello Jane
this is it :
at the k step : b(k) is 600 - sum of a from 1 to k
for t=1:n
a(t)=600+10^t;
b(t)=600-sum(a(1:t));
end
  1 commentaire
Jane Smith
Jane Smith le 5 Mar 2021
worked thank you!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Programming dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by