Symbolic cumulative product

Create a vector and find the cumulative product of its elements.

V = 1./factorial(sym([1:5])) prod_V = cumprod(V)

V = [ 1, 1/2, 1/6, 1/24, 1/120] prod_V = [ 1, 1/2, 1/12, 1/288, 1/34560]

Create matrix a 4-by-4 symbolic matrix `X`

all
elements of which equal `x`

.

syms x X = x*ones(4,4)

X = [ x, x, x, x] [ x, x, x, x] [ x, x, x, x] [ x, x, x, x]

Compute the cumulative product of the elements of `X`

.
By default, `cumprod`

returns the cumulative product
of each column.

productX = cumprod(X)

productX = [ x, x, x, x] [ x^2, x^2, x^2, x^2] [ x^3, x^3, x^3, x^3] [ x^4, x^4, x^4, x^4]

Create matrix a 4-by-4 symbolic matrix, all
elements of which equal `x`

.

syms x X = x*ones(4,4)

X = [ x, x, x, x] [ x, x, x, x] [ x, x, x, x] [ x, x, x, x]

Compute the cumulative product of each row of the matrix `X`

.

productX = cumprod(X,2)

productX = [ x, x^2, x^3, x^4] [ x, x^2, x^3, x^4] [ x, x^2, x^3, x^4] [ x, x^2, x^3, x^4]

Create matrix a 4-by-4 symbolic matrix `X`

all
elements of which equal `x`

.

syms x X = x*ones(4,4)

X = [ x, x, x, x] [ x, x, x, x] [ x, x, x, x] [ x, x, x, x]

Calculate the cumulative product along the columns in both directions.
Specify the `'reverse'`

option to work from right
to left in each row.

columnsDirect = cumprod(X) columnsReverse = cumprod(X,'reverse')

columnsDirect = [ x, x, x, x] [ x^2, x^2, x^2, x^2] [ x^3, x^3, x^3, x^3] [ x^4, x^4, x^4, x^4] columnsReverse = [ x^4, x^4, x^4, x^4] [ x^3, x^3, x^3, x^3] [ x^2, x^2, x^2, x^2] [ x, x, x, x]

Calculate the cumulative product along the rows in both directions.
Specify the `'reverse'`

option to work from right
to left in each row.

rowsDirect = cumprod(X,2) rowsReverse = cumprod(X,2,'reverse')

rowsDirect = [ x, x^2, x^3, x^4] [ x, x^2, x^3, x^4] [ x, x^2, x^3, x^4] [ x, x^2, x^3, x^4] rowsReverse = [ x^4, x^3, x^2, x] [ x^4, x^3, x^2, x] [ x^4, x^3, x^2, x] [ x^4, x^3, x^2, x]