主要内容

cumprod

Symbolic cumulative product

Description

example

B= cumprod(A)returns the cumulative product ofAstarting at the beginning of the first array dimension inA其大小不等于1.输出Bhas the same size asA

  • IfAis a vector, thencumprod(A)returns a vector containing the cumulative product of the elements ofA

  • IfA是矩阵,然后cumprod(A)返回包含每一列的累积产物的矩阵下载188bet金宝搏A

  • IfA是一个多维数组,然后cumprod(A)acts along the第一个nonsingleton维度

example

B= cumprod(A,dim)returns the cumulative product along dimensiondim。例如,如果A是矩阵,然后cumprod(A,2)returns the cumulative product of each row.

example

B= cumprod(___,方向)specifies the direction using any of the previous syntaxes. For instance,cumprod(A,2,'reverse')returns the cumulative product within the rows ofAby working from end to beginning of the second dimension.

example

B= cumprod(___,Nanflag)指定包括还是省略NaNvalues from the calculation for any of the previous syntaxes.cumprod(A,'includenan')includes allNaN计算中的值cumprod(A,'omitnan')ignores them.

Examples

collapse all

Create a symbolic vector. Find the cumulative product of its elements.

symsxA = (1:5)*x
A =
                       
                        
                         
                          
                           (
                          
                           
                            
                             
                              
                               x
                             
                            
                            
                             
                              
                               
                                
                                 2
                                
                                
                                
                                 x
                               
                              
                             
                            
                            
                             
                              
                               
                                
                                 3
                                
                                
                                
                                 x
                               
                              
                             
                            
                            
                             
                              
                               
                                
                                 4
                                
                                
                                
                                 x
                               
                              
                             
                            
                            
                             
                              
                               
                                
                                 5
                                
                                
                                
                                 x
                               
                              
                             
                            
                           
                          
                          
                           )
                         
                        
                       

In the vector of cumulative products, elementB(2)is the product ofA(1)A(2), whileB(5)是元素的产物A(1)throughA(5)

b =cumprod(A)
b =
                       
                        
                         
                          
                           (
                          
                           
                            
                             
                              
                               x
                             
                            
                            
                             
                              
                               
                                
                                 2
                                
                                
                                
                                 
                                  
                                   x
                                 
                                 
                                  
                                   2
                                 
                                
                               
                              
                             
                            
                            
                             
                              
                               
                                
                                 6
                                
                                
                                
                                 
                                  
                                   x
                                 
                                 
                                  
                                   3
                                 
                                
                               
                              
                             
                            
                            
                             
                              
                               
                                
                                 24
                                
                                
                                
                                 
                                  
                                   x
                                 
                                 
                                  
                                   4
                                 
                                
                               
                              
                             
                            
                            
                             
                              
                               
                                
                                 120
                                
                                
                                
                                 
                                  
                                   x
                                 
                                 
                                  
                                   5
                                 
                                
                               
                              
                             
                            
                           
                          
                          
                           )
                         
                        
                       

创建一个3 x-3的符号矩阵A的所有元素x

symsxA = ones(3)*x
A =

( x x x x x x x x x )

Compute the cumulative product of elements ofA。By default,cumprod返回每列的累积产品。

b =cumprod(A)
b =

( x x x x 2 x 2 x 2 x 3 x 3 x 3 )

要计算每一行的累积产品,请设置dim选项2

b =cumprod(A,2)
b =

( x x 2 x 3 x x 2 x 3 x x 2 x 3 )

创建一个3 x-3-BY-2符号阵列。

symsxyA(:,:,1) = [x y 0; x 3 x*y; x 1/3 y]; A(:,:,2) = [x y 3; 3 x y; y 3 x]; A
A(:,:,1) =

( x y 0 x 3 x y x 1 3 y )

A(:,:,2) =

( x y 3 3 x y y 3 x )

Compute the cumulative product along the rows by specifyingdimas2。Specify the“作梦se'选项work from right to left in each row. The result is the same size asA

b =cumprod(A,2,“作梦se')
b(:,::,1)=

( 0 0 0 3 x 2 y 3 x y x y x y 3 y 3 y )

B(:,:,2) =

( 3 x y 3 y 3 3 x y x y y 3 x y 3 x x )

要沿第三(页)维度计算累积产品,请指定dimas3。Specify the“作梦se'从最大的页面索引到最小页面索引的选项。

b =cumprod(A,3,“作梦se')
b(:,::,1)=

( x 2 y 2 0 3 x 3 x x y 2 x y 1 x y )

B(:,:,2) =

( x y 3 3 x y y 3 x )

创建一个包含的符号向量NaN值。计算累积产品。下载188bet金宝搏

A = [sym('a') sym('b') 1 NaN 2]
A =
                       
                        
                         
                          
                           (
                          
                           
                            
                             
                              
                               a
                             
                            
                            
                             
                              
                               b
                             
                            
                            
                             
                              
                               1
                             
                            
                            
                             
                              
                               NaN
                             
                            
                            
                             
                              
                               2
                             
                            
                           
                          
                          
                           )
                         
                        
                       
b =cumprod(A)
b =
                       
                        
                         
                          
                           (
                          
                           
                            
                             
                              
                               a
                             
                            
                            
                             
                              
                               
                                
                                 a
                                
                                
                                
                                 b
                               
                              
                             
                            
                            
                             
                              
                               
                                
                                 a
                                
                                
                                
                                 b
                               
                              
                             
                            
                            
                             
                              
                               NaN
                             
                            
                            
                             
                              
                               NaN
                             
                            
                           
                          
                          
                           )
                         
                        
                       

You can ignoreNaNvalues in the cumulative product calculation using the'omitnan'选项。

b =cumprod(A,'omitnan')
b =
                       
                        
                         
                          
                           (
                          
                           
                            
                             
                              
                               a
                             
                            
                            
                             
                              
                               
                                
                                 a
                                
                                
                                
                                 b
                               
                              
                             
                            
                            
                             
                              
                               
                                
                                 a
                                
                                
                                
                                 b
                               
                              
                             
                            
                            
                             
                              
                               
                                
                                 a
                                
                                
                                
                                 b
                               
                              
                             
                            
                            
                             
                              
                               
                                
                                 2
                                
                                
                                
                                 a
                                
                                
                                
                                 b
                               
                              
                             
                            
                           
                          
                          
                           )
                         
                        
                       

Input Arguments

collapse all

输入阵列,指定为符号向量,矩阵或多维数组。

沿着操作的维度,指定为正整数标量。如果未指定值,则默认值是第一个数组维度,其大小不等于1。

考虑二维输入阵列,A

  • cumprod(A,1)在列的连续元素上工作A和返回每列的累积产品。

  • cumprod(A,2)在行的连续元素上工作A并返回每行的累积产品。

cumprodreturnsAifdim大于ndims(A)

Direction of cumulation, specified as'forward'(default) or“作梦se'

  • 'forward'works from1toend活动尺寸。

  • “作梦se'works fromendto1活动尺寸。

Data Types:char

NaN(健康)状况, specified as:

  • 'includenan'— IncludeNaNvalues from the input when computing the cumulative products, resulting inNaNvalues in the output.

  • 'omitnan'- 忽略所有NaNvalues in the input. The product of elements containingNaNvalues is the product of all non-NaN元素。如果所有元素是NaN, thencumprod返回1。

Data Types:char

Output Arguments

collapse all

Cumulative product array, returned as a vector, matrix, or multidimensional array of the same size as the inputA

More About

collapse all

First Nonsingleton Dimension

The first nonsingleton dimension is the first dimension of an array whose size is not equal to 1.

例如:

  • IfXis a 1-by-n row vector, then the second dimension is the first nonsingleton dimension ofX

  • IfXis a 1-by-0-by-n empty array, then the second dimension is the first nonsingleton dimension ofX

  • IfX是一个1 x-1 x-3阵列,那么第三维是第一个非元素维度。X

Version History

在R2013B中引入