Difference between revisions of "StepInterp"

Line 1: Line 1:
 
[[Category:Interpolation functions]]
 
[[Category:Interpolation functions]]
 
[[Category:Doc Status D]] <!-- For Lumina use, do not change -->
 
[[Category:Doc Status D]] <!-- For Lumina use, do not change -->
+
[[Category:Array Library]]
== StepInterp( D,A,x,I ) ==
+
== StepInterp(d, r, x, ''i'') ==
 +
Given coordinates «d» and «r», indexed by «i», it returns the y value corresponding to the smallest value of d>=x.  Thus, it returns a step function, with risers at each value of «d». If optional parameter «leftLookup» is True, it returns the y value corresponding to the largest value of d<=x. «d», «r», and «x» must be numbers. The numbers in «d» must be in increasing order. If «d» is itself a simple index, «r» must be indexed by «d», and parameter «i» may be omitted.  Otherwise, «i» must be a common index of «d» and «r». «x» may be a scalar or array. If «x» is less than the smallest (and first) value in «d» (x < d[@i=1]), it returns that smallest value. Similarly, if «x» is larger than the last (largest) value in «d» (x > d[@i=Size(i)]), it returns that largest value.
  
Returns the element or slice of array A corresponding to the smallest value in D that is greater than or equal to x. D and A must both be indexed by I, and D must be increasing along index I. If x is greater than all values of D, returns the element for which D has the largest value.
+
If «x» is a single value, the result of [[StepInterp]] is an array indexed by all indexes of «r» except «d»’s index. If «x» is an array, the result of [[Stepinterp]] is also indexed by the indexes of «x».
  
If X is a single value, the result of Stepinterp() is an array indexed by all indexes of A except D’s index. If X is an array, the result of Stepinterp() is also indexed by the indexes of X.
+
[[StepInterp]] is similar to [[Subscript]](u1, i, u2); however, [[Subscript]] selects based on the index value being equal to «x», while [[StepInterp]] selects based on the array value being greater than or equal to «x».  
  
StepInterp() is similar to [[Subscript]](u1, i, u2); however, [[Subscript]]() selects based on the index value being equal to x, while Stepinterp() selects based on the array value being greater than or equal to x.  
+
[[StepInterp]] can be used to perform table lookup.
  
Stepinterp() can be used to perform table lookup.
+
==Examples==
 
+
The following examples use [[Array Function Example Variables]].
==StepInterp( D,A,x,I, LeftLookup:True ) ==
 
 
 
When the optional parameter, LeftLookup, is specified as true, StepInterp returns the element or slice of A corresponding to the largest value in D that is less than or equal to x.
 
 
 
The two graphs interpolate from the same set of ''(d,r)'' points, with different settings for ''LeftLookup''.
 
 
 
{|
 
| [[Image:Stepinterp-graph.png]]  
 
| [[Image:StepInterp2-graph.png]]
 
|-
 
! LeftLookup:False (default)
 
! LeftLookup:True
 
|}
 
 
 
== See Also ==
 
  
* The User Group Webinar [[Analytica_User_Group/Past_Topics#Step_Interpolation|Intro to Step Interpolation]] recording.
+
To see the values in <code>Car_prices</code> corresponding to <code>Years >= 2007.5</code>:
* [[LinearInterp]]
 
* [[CubicInterp]]
 
* [[Subscript]]
 
  
=User Guide=
+
<code>StepInterp(Years, Car_prices, 2007.5, Years) →</code>
Returns the element or slice of array '''y''' for which '''v''' has the smallest value less than or equal to '''x'''. '''x''' and '''y''' must both be indexed by '''i''', and '''x''' must be increasing along index '''i'''. If '''v''' is greater than all values of '''x''', it returns the element of '''y''' for which '''x''' has the largest value.
 
 
 
When an optional parameter, '''LeftLookup''', is specified as True, it returns the element or slice of y corresponding to the ''largest'' value in '''x''' that is less than or equal to '''v'''.
 
 
 
If '''v''' is an atom (scalar value), the result is an array indexed by all indexes of '''a''' except '''x'''’s index. If '''v''' is an array, the result is also indexed by the indexes of '''v'''.
 
 
 
If the first parameter '''x''' is an index of '''y''', the fourth parameter is optional. '''Stepinterp(x, y, v)''' is similar to '''y[x=v]''' except that '''y[x=v]''' selects based on '''v''' being equal to '''x''', while '''Stepinterp(x, y, v)''' selects based on '''v''' being ''greater'' than or equal to '''x'''.
 
 
 
'''Stepinterp()''' can be used to perform table lookup.
 
 
 
==Library==
 
Array
 
 
 
==Examples==
 
To see the values in <tt>Car_prices</tt> corresponding to <tt>Years >= 2007.5</tt>:
 
Stepinterp(Years, Car_prices, 2007.5, Years) →
 
Car_type >
 
 
{| class="wikitable"
 
{| class="wikitable"
 +
!! colspan="3" style="text-align: left;" | Car_type &#9654;
 
|-
 
|-
 
! scope="col"| VW
 
! scope="col"| VW
Line 63: Line 30:
  
 
Here '''v''' is a list of two values:
 
Here '''v''' is a list of two values:
Stepinterp(Years, Car_prices, [2007,2008], Years) →
+
 
 +
<code>StepInterp(Years, Car_prices, [2007,2008], Years) →</code>
 
{| class="wikitable"
 
{| class="wikitable"
 
|-
 
|-
Line 81: Line 49:
 
| 30K
 
| 30K
 
|}
 
|}
 +
 +
==Optional Parameters==
 +
=== ''i'' ===
 +
Specifies the common index of «d» and «r». You can omit this, if «d» is itself an index of «r».
 +
 +
=== ''extrapolationMethod'' ===
 +
Specifies the value to return if «x» is outside the values of «d»:
 +
*1: Use the «r» for nearest «d» (default method)
 +
*2: Return [[Null]]
 +
*3: Same as 1 (nearest point) for normal evaluation, but [[Null]] during optimization.
 +
 +
=== ''leftLookup'' ===
 +
When the optional parameter, «leftLookup», is specified as True, [[StepInterp]] returns the element or slice of «r» corresponding to the largest value in «d» that is less than or equal to «x».
 +
 +
The two graphs interpolate from the same set of ''(d,r)'' points, with different settings for «leftLookup».
 +
{|
 +
| [[Image:Stepinterp-graph.png|450px]]
 +
| [[Image:StepInterp2-graph.png|450px]]
 +
|-
 +
! leftLookup:False (default)
 +
! leftLookup:True
 +
|}
 +
 +
== See Also ==
 +
* The User Group Webinar [[Analytica_User_Group/Past_Topics#Step_Interpolation|Intro to Step Interpolation]] recording.
 +
* [[LinearInterp]]
 +
* [[CubicInterp]]
 +
* [[Subscript]]

Revision as of 01:12, 30 October 2015

StepInterp(d, r, x, i)

Given coordinates «d» and «r», indexed by «i», it returns the y value corresponding to the smallest value of d>=x. Thus, it returns a step function, with risers at each value of «d». If optional parameter «leftLookup» is True, it returns the y value corresponding to the largest value of d<=x. «d», «r», and «x» must be numbers. The numbers in «d» must be in increasing order. If «d» is itself a simple index, «r» must be indexed by «d», and parameter «i» may be omitted. Otherwise, «i» must be a common index of «d» and «r». «x» may be a scalar or array. If «x» is less than the smallest (and first) value in «d» (x < d[@i=1]), it returns that smallest value. Similarly, if «x» is larger than the last (largest) value in «d» (x > d[@i=Size(i)]), it returns that largest value.

If «x» is a single value, the result of StepInterp is an array indexed by all indexes of «r» except «d»’s index. If «x» is an array, the result of Stepinterp is also indexed by the indexes of «x».

StepInterp is similar to Subscript(u1, i, u2); however, Subscript selects based on the index value being equal to «x», while StepInterp selects based on the array value being greater than or equal to «x».

StepInterp can be used to perform table lookup.

Examples

The following examples use Array Function Example Variables.

To see the values in Car_prices corresponding to Years >= 2007.5:

StepInterp(Years, Car_prices, 2007.5, Years) →

Car_type ▶
VW Honda BMW
19 22 30

Here v is a list of two values:

StepInterp(Years, Car_prices, [2007,2008], Years) →

VW Honda BMW
2007 18K 20K 28K
2008 19K 22K 30K

Optional Parameters

i

Specifies the common index of «d» and «r». You can omit this, if «d» is itself an index of «r».

extrapolationMethod

Specifies the value to return if «x» is outside the values of «d»:

  • 1: Use the «r» for nearest «d» (default method)
  • 2: Return Null
  • 3: Same as 1 (nearest point) for normal evaluation, but Null during optimization.

leftLookup

When the optional parameter, «leftLookup», is specified as True, StepInterp returns the element or slice of «r» corresponding to the largest value in «d» that is less than or equal to «x».

The two graphs interpolate from the same set of (d,r) points, with different settings for «leftLookup».

Stepinterp-graph.png StepInterp2-graph.png
leftLookup:False (default) leftLookup:True

See Also

Comments


You are not allowed to post comments.