Vectorize sum of discount rates

조회 수: 4 (최근 30일)
Sargondjani
Sargondjani 2012년 12월 6일
Hi,
I want to vectorize the calculation of series like this: [R^0;R^0+R^1;R^0+R^1+R^2;...etc.
Im quite sure this should be easy, but i cant figure it out. Any help is greatly appreciated! :-)

채택된 답변

Matt Fig
Matt Fig 2012년 12월 6일
R = 5;
cumsum(R.^(0:4))

추가 답변 (3개)

Matt J
Matt J 2012년 12월 6일
편집: Matt J 2012년 12월 6일
out=1/(1-R).*(1-R.^(1:n));

Jan
Jan 2012년 12월 6일
R = 23;
n = 100;
x = repmat(R, 1, n);
x(1) = 1;
Result = cumsum(cumprod(x));

Sargondjani
Sargondjani 2012년 12월 6일
thank you all for you answers... all did what i wanted, but the one by Matt Fig is the most simple

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by