MATLAB Answers

0

Vectorize sum of discount rates

Asked by Sargondjani on 6 Dec 2012
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! :-)

  1 Comment

Jan
on 6 Dec 2012
What is "R"?

Sign in to comment.

4 Answers

Answer by Matt Fig
on 6 Dec 2012
 Accepted Answer

R = 5;
cumsum(R.^(0:4))

  0 Comments

Sign in to comment.


Matt J
Answer by Matt J
on 6 Dec 2012
Edited by Matt J
on 6 Dec 2012

out=1/(1-R).*(1-R.^(1:n));

  0 Comments

Sign in to comment.


Jan
Answer by Jan
on 6 Dec 2012

R = 23;
n = 100;
x = repmat(R, 1, n);
x(1) = 1;
Result = cumsum(cumprod(x));

  0 Comments

Sign in to comment.


Answer by Sargondjani on 6 Dec 2012

thank you all for you answers... all did what i wanted, but the one by Matt Fig is the most simple

  0 Comments

Sign in to comment.