Difference between revisions of "CumProduct"
(see also - CumMin and CumMax) |
|||
(7 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
[[Category:Doc Status C]] <!-- For Lumina use, do not change --> | [[Category:Doc Status C]] <!-- For Lumina use, do not change --> | ||
− | = CumProduct( | + | == CumProduct(X, I) == |
+ | Returns an array with each element being the product of all of the elements of «X» along dimension «I» up to, and including, the corresponding element of «X». | ||
− | + | [[Syntax]]: | |
+ | :[[CumProduct]](X: Array[I]; I: Index, passNull: optional Boolean, reset: optional Array) | ||
− | = Examples = | + | == Examples == |
+ | :<code>I := </code> | ||
+ | ::<code>[1, 2, 3, 4, 5, 6, 7]</code> | ||
+ | :<code>X := </code> | ||
+ | ::<code>[[Array]](I, [8, 2, 1, 5, -3, 0, 4])</code> | ||
+ | :<code>CumProduct(X, I) →</code> | ||
+ | ::<code>[8, 16, 16, 80, -240, 0, 0]</code> { indexed by <code>I</code>} | ||
− | = Library = | + | == Library == |
+ | Array functions | ||
+ | |||
+ | == Optional Parameters == | ||
+ | === PassNull === | ||
+ | «PassNull» is an optional boolean parameter that defaults to <code>False</code>. When it is omitted or explicitly set to <code>False</code>, [[CumProduct]] ignores [[Null]] values. In that case they have essentially the same effect as a one, unless they happen to be the first value in «X», in which case they are passed since no numeric values are yet obtained. | ||
+ | |||
+ | When «passNull» is explicitly set to true, then [[Null]] values are passed through as [[Null]] in the result. | ||
− | + | :<code>X := </code> | |
+ | ::<code>[«null», «null», 4, 2, «null», «null», 2, -1, 3, 2, «null»]</code> | ||
+ | :<code>CumProduct(X, I) →</code> | ||
+ | ::<code>[«null», «null», 4, 8, 8, 8, 16, -16, -48, -96, -96]</code> | ||
+ | :<code>CumProduct(X, I, passNull: false) →</code> | ||
+ | ::<code>[«null», «null», 4, 8, 8, 8,16, -16, -48, -96, -96]</code> | ||
+ | :<code>CumProduct(X, I, passNull: true) →</code> | ||
+ | ::<code>[«null», «null», 4, 8, «null», «null», 16, -16, -48, -96, «null»]</code> | ||
+ | |||
+ | === Reset === | ||
+ | The optional «reset» parameter accepts an array of boolean values indexed by «I». At the positions where «reset» is true, [[CumProduct]] starts over. This sets the sum of all previous values to zero, so that the value at that position will be the same as the value in «X». | ||
+ | |||
+ | :<code>I := </code> | ||
+ | ::<code>[1, 2, 3, 4, 5, 6, 7]</code> | ||
+ | :<code>X := </code> | ||
+ | ::<code>[8, 2, 1, 5, -3, 7, 5]</code> | ||
+ | :<code>R := </code> | ||
+ | ::<code> [0, 0, 1, 0, 0, 1, 0]</code> | ||
+ | :<code>CumProduct(X, I, reset: R) →</code> | ||
+ | ::<code>[8, 16, 1, 5, -15, 7, 35]</code> | ||
+ | |||
+ | «Reset» can be used to restart the cumulation each time some state change occurs. In such a scenario, the «reset» parameter is set to <code>True</code> at the first instant (along «I») that the system is in the new state. | ||
− | = | + | Suppose <code>IntRate</code> is the monthly interest rate, indexed by <code>Month</code>. We'll assume the elements of <code>Month</code> are numeric dates corresponding to the first of each month. The following would compute the interest accrued up through the end of each month so far in the current year: |
+ | :<code>CumProduct((1 + IntRate), Month, Reset: DatePart(Month,"M") = 1 ) - 1</code> | ||
+ | == See Also == | ||
* [[Product]] | * [[Product]] | ||
* [[Cumulate]] | * [[Cumulate]] | ||
+ | * [[CumMin and CumMax]] |
Latest revision as of 00:10, 20 June 2019
CumProduct(X, I)
Returns an array with each element being the product of all of the elements of «X» along dimension «I» up to, and including, the corresponding element of «X».
- CumProduct(X: Array[I]; I: Index, passNull: optional Boolean, reset: optional Array)
Examples
I :=
[1, 2, 3, 4, 5, 6, 7]
X :=
Array(I, [8, 2, 1, 5, -3, 0, 4])
CumProduct(X, I) →
[8, 16, 16, 80, -240, 0, 0]
{ indexed byI
}
Library
Array functions
Optional Parameters
PassNull
«PassNull» is an optional boolean parameter that defaults to False
. When it is omitted or explicitly set to False
, CumProduct ignores Null values. In that case they have essentially the same effect as a one, unless they happen to be the first value in «X», in which case they are passed since no numeric values are yet obtained.
When «passNull» is explicitly set to true, then Null values are passed through as Null in the result.
X :=
[«null», «null», 4, 2, «null», «null», 2, -1, 3, 2, «null»]
CumProduct(X, I) →
[«null», «null», 4, 8, 8, 8, 16, -16, -48, -96, -96]
CumProduct(X, I, passNull: false) →
[«null», «null», 4, 8, 8, 8,16, -16, -48, -96, -96]
CumProduct(X, I, passNull: true) →
[«null», «null», 4, 8, «null», «null», 16, -16, -48, -96, «null»]
Reset
The optional «reset» parameter accepts an array of boolean values indexed by «I». At the positions where «reset» is true, CumProduct starts over. This sets the sum of all previous values to zero, so that the value at that position will be the same as the value in «X».
I :=
[1, 2, 3, 4, 5, 6, 7]
X :=
[8, 2, 1, 5, -3, 7, 5]
R :=
[0, 0, 1, 0, 0, 1, 0]
CumProduct(X, I, reset: R) →
[8, 16, 1, 5, -15, 7, 35]
«Reset» can be used to restart the cumulation each time some state change occurs. In such a scenario, the «reset» parameter is set to True
at the first instant (along «I») that the system is in the new state.
Suppose IntRate
is the monthly interest rate, indexed by Month
. We'll assume the elements of Month
are numeric dates corresponding to the first of each month. The following would compute the interest accrued up through the end of each month so far in the current year:
CumProduct((1 + IntRate), Month, Reset: DatePart(Month,"M") = 1 ) - 1
Enable comment auto-refresher