how to calculate row values based on the previous row value of a column?

input array
a= [1,2,3,4,5,6,7,8,9,10]
the output array is as follows. where 100 is initial value we are calculating for 1. for 2 we are taking output of 1.
b= (1*100)+100 = 200
b = (2*200)+ 200 = 600
b=(3*600)+600 = 2400
like wise i need to calculate for all elements of a.

 Réponse acceptée

a= [1,2,3,4,5,6,7,8,9,10];
b = 100; % initial value
for i=1:numel(a)
b= (a(i)*b)+b;
fprintf("i=%2d b=%d\n", i, b)
end
i= 1 b=200 i= 2 b=600 i= 3 b=2400 i= 4 b=12000 i= 5 b=72000 i= 6 b=504000 i= 7 b=4032000 i= 8 b=36288000 i= 9 b=362880000 i=10 b=3991680000

Plus de réponses (0)

Catégories

En savoir plus sur Elementary Math 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!

Translated by