Difference between revisions of "Transforming functions"

Line 96: Line 96:
 
|}
 
|}
  
<code>Cumulate(Cost_of_ownership,Car_type, reset:Time=2) &rarr;</code>
+
<code>Cumulate(Cost_of_ownership, Car_type, reset: Time = 2) &rarr;</code>
 
{| class="wikitable" border="1"  
 
{| class="wikitable" border="1"  
 
! !! colspan="5" style="text-align: left;" | Years &#9654;
 
! !! colspan="5" style="text-align: left;" | Years &#9654;
Line 130: Line 130:
  
 
''See [[Array Function Example Variables]] for example array variables used here and below.''
 
''See [[Array Function Example Variables]] for example array variables used here and below.''
 +
 +
==Uncumulate(x, i, ''firstElement'')==
 +
'''Uncumulate(x, i)''' returns an array whose first element (along '''i''') is the first element of '''x''', and each other element is the difference between the corresponding element of '''x''' and the previous element of '''x'''. '''Uncumulate(x, i, firstElement)''' returns an array with the first element along '''i''' equal to '''firstElement''', and each other element equal to the difference between the corresponding element of '''x''' and the previous element of '''x'''.
 +
 +
'''Uncumulate(x, i)''' is the inverse of '''Cumulate(x, i)'''. '''Uncumulate(x, i, 0)''' is similar to a discrete differential operator.
 +
 +
'''Library:''' Array
 +
 +
'''Example:'''
 +
 +
<code>Uncumulate(Cost_of_ownership, Time) &rarr;</code>
 +
 +
{| class="wikitable" border="1"
 +
! !! colspan="5" style="text-align: left;" | Years &#9654;
 +
|-
 +
! style="width:100px;" |'''Car_type &#9660; '''
 +
! style="width:75px;" |'''0            '''
 +
! style="width:75px;" |'''1            '''
 +
! style="width:75px;" |'''2            '''
 +
! style="width:75px;" |'''3            '''
 +
! style="width:75px;" |'''4            '''
 +
|-
 +
!'''VW'''
 +
| 2810
 +
| 141
 +
| 147
 +
| 155
 +
| 163
 +
|-
 +
!'''Honda '''
 +
| 3535
 +
| 312
 +
| 50
 +
| 269
 +
| 199
 +
|-
 +
!'''BMW'''
 +
| 3185
 +
| 109
 +
| 115
 +
| 120
 +
| 127
 +
|}
 +
 +
<code>Uncumulate(Cost_of_ownership, Time,0) &rarr;</code>
 +
 +
{| class="wikitable" border="1"
 +
! !! colspan="5" style="text-align: left;" | Years &#9654;
 +
|-
 +
! style="width:100px;" |'''Car_type &#9660; '''
 +
! style="width:75px;" |'''0            '''
 +
! style="width:75px;" |'''1            '''
 +
! style="width:75px;" |'''2            '''
 +
! style="width:75px;" |'''3            '''
 +
! style="width:75px;" |'''4            '''
 +
|-
 +
!'''VW'''
 +
| 0
 +
| 141
 +
| 147
 +
| 155
 +
| 163
 +
|-
 +
!'''Honda '''
 +
| 0
 +
| 312
 +
| 50
 +
| 269
 +
| 199
 +
|-
 +
!'''BMW'''
 +
| 0
 +
| 109
 +
| 115
 +
| 120
 +
| 127
 +
|}
 +
 +
''See [[Array Function Example Variables]] for example array variables used here and below.''
 +
 +
==CumProduct(x, i, passNull, reset)==
 +
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'''.
 +
 +
For a description of the optional parameters, passNull and reset, see function [[Transforming functions#Cumulate(x, i, ''passNull, reset'')|Cumulate(x, i, passNull, reset)]].
 +
 +
'''Library:''' Array
 +
 +
'''Example:'''
 +
 +
<code>Cumproduct(Rate_of_inflation, Years) &rarr;</code>
 +
{| class="wikitable" border="1"
 +
! colspan="5" style="text-align: left;" | Years &#9654;
 +
|-
 +
! style="width:75px;" |'''2005            '''
 +
! style="width:75px;" |'''2006            '''
 +
! style="width:75px;" |'''2007            '''
 +
! style="width:75px;" |'''2008            '''
 +
! style="width:75px;" |'''2009            '''
 +
|-
 +
| 1
 +
| 1.01
 +
| 1.03
 +
| 1.061
 +
| 1.104
 +
|}
 +
 
==See Also==
 
==See Also==
 
<footer>Array-reducing functions / {{PAGENAME}} / Relational tables and multiD arrays</footer>
 
<footer>Array-reducing functions / {{PAGENAME}} / Relational tables and multiD arrays</footer>

Revision as of 22:33, 11 December 2015

A transforming function operates across a dimension of an array and returns a result that has the same dimensions as its input array.

The function Cumulate(x, i) illustrates some properties of transforming functions.

Example:

Cumulate(Car_prices, Years) →

Years ▶
Car_type ▼ 2005 2006 2007 2008 2009
VW 16K 33K 51K 70K 90K
Honda 18K 37K 57K 79K 103K
BMW 25K 51K 79K 109K 141K

The second parameter, i, specifying the dimension over which to cumulate, is optional. But if the array, x, has more than one dimension, Analytica might not cumulate over the dimension you expect. For this reason, it is safer always to specify the dimension index explicitly in any transforming function.

Cumulate(x, i, passNull, reset)

Returns an array with each element being the sum of all of the elements of x along dimension i up to, and including, the corresponding element of x.

Cumulate(1, i) is equivalent to @i, where each numbers the elements of an index.

The optional passNull parameter controls now null values in x are passed through to the result.If passNull is false or omitted, then null values in x are ignored and do not effect the cumulation. Leading null values will be passed through, but after a numeric value is encountered, nullvalues in x will cumulate the same as zero.

The optional reset parameter, an array of boolean values along i, can be used to indicate points along i where you want to restart the cumulation. For example, if you want to restart the cumulation following a state change, reset can be set to true each time a new state is entered.

Library: Array

Example:

Cumulate(Cost_of_ownership, Time) →

Years ▶
Car_type ▼ 0 1 2 3 4
VW 2810 5761 8859 12.11K 15.53K
Honda 3535 7382 11.28K 15.45K 19.81K
BMW 3185 6479 9888 13.42K 17.07K

Cumulate(Cost_of_ownership, Car_type, reset: Time = 2) →

Years ▶
Car_type ▼ 0 1 2 3 4
VW 2810 5761 3098 6351K 9767K
Honda 3535 7382 3897K 8063K 12.43K
BMW 3185 6479 3409 6938K 10.59K

See Array Function Example Variables for example array variables used here and below.

Uncumulate(x, i, firstElement)

Uncumulate(x, i) returns an array whose first element (along i) is the first element of x, and each other element is the difference between the corresponding element of x and the previous element of x. Uncumulate(x, i, firstElement) returns an array with the first element along i equal to firstElement, and each other element equal to the difference between the corresponding element of x and the previous element of x.

Uncumulate(x, i) is the inverse of Cumulate(x, i). Uncumulate(x, i, 0) is similar to a discrete differential operator.

Library: Array

Example:

Uncumulate(Cost_of_ownership, Time) →

Years ▶
Car_type ▼ 0 1 2 3 4
VW 2810 141 147 155 163
Honda 3535 312 50 269 199
BMW 3185 109 115 120 127

Uncumulate(Cost_of_ownership, Time,0) →

Years ▶
Car_type ▼ 0 1 2 3 4
VW 0 141 147 155 163
Honda 0 312 50 269 199
BMW 0 109 115 120 127

See Array Function Example Variables for example array variables used here and below.

CumProduct(x, i, passNull, reset)

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.

For a description of the optional parameters, passNull and reset, see function Cumulate(x, i, passNull, reset).

Library: Array

Example:

Cumproduct(Rate_of_inflation, Years) →

Years ▶
2005 2006 2007 2008 2009
1 1.01 1.03 1.061 1.104

See Also

Comments


You are not allowed to post comments.