Difference between revisions of "StepInterp"
m (→See Also) |
|||
Line 2: | Line 2: | ||
[[Category:Doc Status D]] <!-- For Lumina use, do not change --> | [[Category:Doc Status D]] <!-- For Lumina use, do not change --> | ||
[[Category:Array Library]] | [[Category:Array Library]] | ||
+ | |||
== StepInterp(xi, yi, x, ''i'') == | == StepInterp(xi, yi, x, ''i'') == | ||
− | Given arrays of numerical coordinates «xi» and «yi», indexed by «i», it returns the y value corresponding to the smallest value of xi>=x. Thus, it returns a step function, with risers at each value of «xi». If optional parameter «leftLookup» is <code>True</code>, it returns the y value corresponding to the largest value of xi<=x. «xi», «yi», and «x» must be numbers. The numbers in «xi» must be in increasing order. If «xi» is itself a simple index, «yi» must be indexed by «xi», and parameter «i» may be omitted. Otherwise, «i» must be a common index of «xi» and «yi». «x» may be a scalar or array. If «x» is less than the smallest (and first) value in «xi» (x < xi[@i=1]), it returns that smallest value. Similarly, if «x» is larger than the last (largest) value in «xi» (x > xi[@i=Size(i)]), it returns that largest value. | + | Given arrays of numerical coordinates «xi» and «yi», indexed by «i», it returns the y value corresponding to the smallest value of xi>=x. Thus, it returns a step function, with risers at each value of «xi». If optional parameter «leftLookup» is <code>True</code>, it returns the y value corresponding to the largest value of xi<=x. «xi», «yi», and «x» must be numbers. The numbers in «xi» must be in increasing order. If «xi» is itself a simple index, «yi» must be indexed by «xi», and parameter «i» may be omitted. Otherwise, «i» must be a common index of «xi» and «yi». «x» may be a scalar or array. If «x» is less than the smallest (and first) value in «xi» (''x < xi[@i = 1]''), it returns that smallest value. Similarly, if «x» is larger than the last (largest) value in «xi» (''x > xi[@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 «yi» except «xi»’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 «yi» except «xi»’s index. If «x» is an array, the result of [[Stepinterp]] is also indexed by the indexes of «x». | ||
Line 16: | Line 17: | ||
To see the values in <code>Car_prices</code> corresponding to <code>Years >= 2007.5</code>: | To see the values in <code>Car_prices</code> corresponding to <code>Years >= 2007.5</code>: | ||
− | <code>StepInterp(Years, Car_prices, 2007.5, Years) | + | :<code>StepInterp(Years, Car_prices, 2007.5, Years) →</code> |
− | {| class="wikitable" | + | :{| class="wikitable" |
− | !! colspan="3 | + | !! colspan="3" | Car_type ▶ |
|- | |- | ||
! scope="col"| VW | ! scope="col"| VW | ||
Line 31: | Line 32: | ||
Here '''v''' is a list of two values: | Here '''v''' is a list of two values: | ||
− | <code>StepInterp(Years, Car_prices, [2007,2008], Years) | + | :<code>StepInterp(Years, Car_prices, [2007, 2008], Years) →</code> |
− | {| class="wikitable" | + | :{| class="wikitable" |
|- | |- | ||
! scope="col"| | ! scope="col"| | ||
Line 56: | Line 57: | ||
=== ''extrapolationMethod'' === | === ''extrapolationMethod'' === | ||
Specifies the value to return if «x» is outside the values of «xi»: | Specifies the value to return if «x» is outside the values of «xi»: | ||
− | *1: Use the «yi» for nearest «xi» (default method) | + | *<code>1</code>: Use the «yi» for nearest «xi» (default method) |
− | *2: Return [[Null]] | + | *<code>2</code>: Return [[Null]] |
− | *3: Same as 1 (nearest point) for normal evaluation, but [[Null]] during optimization. | + | *<code>3</code>: Same as <code>1</code> (nearest point) for normal evaluation, but [[Null]] during optimization. |
=== ''leftLookup'' === | === ''leftLookup'' === | ||
When the optional parameter, «leftLookup», is specified as <code>True</code>, [[StepInterp]] returns the element or slice of «yi» corresponding to the largest value in «xi» that is less than or equal to «x». | When the optional parameter, «leftLookup», is specified as <code>True</code>, [[StepInterp]] returns the element or slice of «yi» corresponding to the largest value in «xi» that is less than or equal to «x». | ||
− | The two graphs interpolate from the same set of ''(xi,yi)'' points, with different settings for «leftLookup». | + | The two graphs interpolate from the same set of ''(xi, yi)'' points, with different settings for «leftLookup». |
{| | {| | ||
| [[Image:Stepinterp-graph.png|450px]] | | [[Image:Stepinterp-graph.png|450px]] | ||
| [[Image:StepInterp2-graph.png|450px]] | | [[Image:StepInterp2-graph.png|450px]] | ||
|- | |- | ||
− | + | | <center><code>leftLookup: False</code> (default) </center> | |
− | + | | <center><code>leftLookup: True</code></center> | |
|} | |} | ||
Revision as of 23:10, 22 January 2016
StepInterp(xi, yi, x, i)
Given arrays of numerical coordinates «xi» and «yi», indexed by «i», it returns the y value corresponding to the smallest value of xi>=x. Thus, it returns a step function, with risers at each value of «xi». If optional parameter «leftLookup» is True
, it returns the y value corresponding to the largest value of xi<=x. «xi», «yi», and «x» must be numbers. The numbers in «xi» must be in increasing order. If «xi» is itself a simple index, «yi» must be indexed by «xi», and parameter «i» may be omitted. Otherwise, «i» must be a common index of «xi» and «yi». «x» may be a scalar or array. If «x» is less than the smallest (and first) value in «xi» (x < xi[@i = 1]), it returns that smallest value. Similarly, if «x» is larger than the last (largest) value in «xi» (x > xi[@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 «yi» except «xi»’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 User Guide Examples.
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 «xi» and «yi». You can omit this, if «xi» is itself an index of «yi».
extrapolationMethod
Specifies the value to return if «x» is outside the values of «xi»:
1
: Use the «yi» for nearest «xi» (default method)2
: Return Null3
: Same as1
(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 «yi» corresponding to the largest value in «xi» that is less than or equal to «x».
The two graphs interpolate from the same set of (xi, yi) points, with different settings for «leftLookup».
![]() |
![]() |
leftLookup: False (default) |
leftLookup: True |
See Also
- The User Group Webinar Intro to Step Interpolation recording.
- LinearInterp
- CubicInterp
- MonoCubicInterp
- Subscript
- User Guide Examples / Array Function Examples.ana / Interpolation Functions Module
Enable comment auto-refresher