Difference between revisions of "StepInterp"

 
(14 intermediate revisions by 3 users not shown)
Line 1: Line 1:
 
[[Category:Interpolation functions]]
 
[[Category:Interpolation functions]]
[[Category:Doc Status D]] <!-- For Lumina use, do not change -->
 
 
[[Category:Array Library]]  
 
[[Category:Array Library]]  
== 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».
+
{{ReleaseBar}}
 +
 
 +
[[StepInterp]] is a lookup function which finds which interval along «xi» a value «x» lands in, and returns the corresponding «yi» for that interval.
 +
 
 +
== StepInterp(xi, yi, x, ''i{{Release|5.3||, use}}'') ==
 +
Given  arrays of coordinates «xi» and «yi», indexed by «i», it returns the «yi» value corresponding to the smallest value in «xi» with <code>xi &ge; x</code>.  Thus, it returns a step function, with risers at each value of «xi». If optional parameter {{Release||5.2|«leftLookup» is <code>True</code>}}{{Release|5.3||«use» is <code>'Left'</code>}}, it returns the y value corresponding to the largest value of «xi» &le; x{{Release|5.3||, and if «use» is <code>'Nearest'</code> it returns the «yi» value corresponding to the «xi» that is closest to «x»}}. «xi», «yi», and «x» do not need to be numbers. The values 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» (<code>x < xi[@i = 1]</code>), it returns that smallest value. Similarly, if «x» is larger than the last (largest) value in «xi» (<code>x > xi[@i = [[IndexLength]](i)]</code>), 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]] 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».  
Line 12: Line 16:
  
 
==Examples==
 
==Examples==
The following examples use [[Array Function Example Variables]].
+
The following examples use [[User Guide Examples]].
  
 
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>
+
:<code>StepInterp(Years, Car_prices, 2007.5, Years) &rarr;</code>
{| class="wikitable"
+
:{| class="wikitable"
!! colspan="3" style="text-align: left;" | Car_type &#9654;
+
!! colspan="3" | Car_type &#9654;
 
|-
 
|-
 
! scope="col"| VW
 
! scope="col"| VW
Line 31: Line 35:
 
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>
+
:<code>StepInterp(Years, Car_prices, [2007, 2008], Years) &rarr;</code>
{| class="wikitable"
+
:{| class="wikitable"
 
|-
 
|-
 
! scope="col"|  
 
! scope="col"|  
Line 51: Line 55:
  
 
==Optional Parameters==
 
==Optional Parameters==
=== ''i'' ===
+
=== «i» ===
Specifies the common index of «d» and «r». You can omit this, if «d» is itself an index of «r».
+
Specifies the common index of «xi» and «yi». You can omit this, if «xi» is itself an index of «yi».
 +
 
 +
=== {{Release||5.2|«leftLookup»}}{{Release|5.3||«use»}} ===
  
=== ''extrapolationMethod'' ===
+
{{Release|5.3||
Specifies the value to return if «x» is outside the values of «d»:
+
(''new to [[Analytica 5.3]]'')
*1: Use the «r» for nearest «d» (default method)
+
The optional «use» parameter can be any one the following:
*2: Return [[Null]]
+
* <code>'Left'</code>: Find the closest value in «xi» to the left of «x».
*3: Same as 1 (nearest point) for normal evaluation, but [[Null]] during optimization.
+
* <code>'NearestL'</code>: Find the closest value in «xi» to «x». Break ties by using the one to the left.
 +
* <code>'Nearest'</code>: Same as <code>'NearestR'</code>
 +
* <code>'NearestR'</code>: Find the closest value in «xi» to «x». Break ties by using the one to the right.
 +
* <code>'Right'</code>: (default) Find the closest value in  «xi» to the right of «x».
 +
}}
  
=== ''leftLookup'' ===
+
{{Release||5.2|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 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».
+
The two graphs interpolate from the same set of ''(xi, yi)'' points, with different settings for {{Release||5.2|«leftLookup»}}{{Release|5.3||«use»}}.
 
{|
 
{|
 
| [[Image:Stepinterp-graph.png|450px]]  
 
| [[Image:Stepinterp-graph.png|450px]]  
 
| [[Image:StepInterp2-graph.png|450px]]
 
| [[Image:StepInterp2-graph.png|450px]]
 
|-
 
|-
! leftLookup:False (default)  
+
| <center><code>{{Release||5.2|leftLookup: False}}{{Release|5.3||use:'Right'}}</code> (default) </center>
! leftLookup:True
+
| <center><code>{{Release||5.2|leftLookup: True}}{{Release|5.3||use:'Left'}}</code></center>
 
|}
 
|}
  
Line 76: Line 85:
 
* [[LinearInterp]]
 
* [[LinearInterp]]
 
* [[CubicInterp]]
 
* [[CubicInterp]]
* [[Subscript]]
+
* [[MonoCubicInterp]]
 +
* [[SubIndex]] -- used to find an exact match in the body cells of an array.
 +
* [[Subscript]] -- used to find an exact match in the index values.
 +
*[[User Guide Examples]] / [[Media: Array Function Examples.ana | Array Function Examples.ana]] / Interpolation Functions Module

Latest revision as of 16:49, 2 November 2021




Release:

4.6  •  5.0  •  5.1  •  5.2  •  5.3  •  5.4  •  6.0  •  6.1  •  6.2  •  6.3  •  6.4  •  6.5


StepInterp is a lookup function which finds which interval along «xi» a value «x» lands in, and returns the corresponding «yi» for that interval.

StepInterp(xi, yi, x, i, use)

Given arrays of coordinates «xi» and «yi», indexed by «i», it returns the «yi» value corresponding to the smallest value in «xi» with xi ≥ x. Thus, it returns a step function, with risers at each value of «xi». If optional parameter «use» is 'Left', it returns the y value corresponding to the largest value of «xi» ≤ x, and if «use» is 'Nearest' it returns the «yi» value corresponding to the «xi» that is closest to «x». «xi», «yi», and «x» do not need to be numbers. The values 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 = IndexLength(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».

«use»

(new to Analytica 5.3) The optional «use» parameter can be any one the following:

  • 'Left': Find the closest value in «xi» to the left of «x».
  • 'NearestL': Find the closest value in «xi» to «x». Break ties by using the one to the left.
  • 'Nearest': Same as 'NearestR'
  • 'NearestR': Find the closest value in «xi» to «x». Break ties by using the one to the right.
  • 'Right': (default) Find the closest value in «xi» to the right of «x».


The two graphs interpolate from the same set of (xi, yi) points, with different settings for «use».

Stepinterp-graph.png StepInterp2-graph.png
use:'Right' (default)
use:'Left'

See Also

Comments


You are not allowed to post comments.