Serving the Quantitative Finance Community

 
User avatar
amitbatra
Topic Author
Posts: 4
Joined: February 13th, 2006, 5:57 pm

Matlab question : Chain addition and multiplication

August 13th, 2007, 10:46 am

Hi All,Is there an inbuilt matlab command for performing chain (recirsive or I don't know what to call it), addition and multiplication.In the sense, a=[1, 2, 3, 4]Applying rcursive_addition(a) should yield [1, 1+2, 1+2+3, 1+2+3+4].And similarly multiplication.I do not want to use 'for' loop.Thanks for your attention.
 
User avatar
mikeoz
Posts: 1
Joined: September 28th, 2005, 2:58 pm

Matlab question : Chain addition and multiplication

August 13th, 2007, 10:50 am

cumsum(a) and cumprod(a)
 
User avatar
amitbatra
Topic Author
Posts: 4
Joined: February 13th, 2006, 5:57 pm

Matlab question : Chain addition and multiplication

August 13th, 2007, 3:41 pm

so I was only a minute away from my answer... thanks so much mikeoz.
 
User avatar
msperlin
Posts: 5
Joined: July 10th, 2006, 6:21 pm

Matlab question : Chain addition and multiplication

August 14th, 2007, 7:22 pm

Also take a look at filter() for the cases where you want to sum x elem at a time. It is flexible (eg. sum only the t-3 and t-1) and extremely fast.For products it would not suit though....