Difference between revisions of "StepInterp"

 
(16 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]]  
 
= StepInterp( D,A,x,I ) =
 
  
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.
+
{{ReleaseBar}}
  
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 a lookup function which finds which interval along «xi» a value «x» lands in, and returns the corresponding «yi» for that interval.
  
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(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.
  
Stepinterp() can be used to perform table lookup.
+
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( D,A,x,I, LeftLookup:True ) =
+
[[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».
  
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.
+
[[StepInterp]] can be used to perform table lookup.
  
The two graphs interpolate from the same set of ''(d,r)'' points, with different settings for ''LeftLookup''.
+
==Examples==
 +
The following examples use [[User Guide Examples]].
  
 +
To see the values in <code>Car_prices</code> corresponding to <code>Years >= 2007.5</code>:
 +
 +
:<code>StepInterp(Years, Car_prices, 2007.5, Years) &rarr;</code>
 +
:{| class="wikitable"
 +
!! colspan="3" | Car_type &#9654;
 +
|-
 +
! scope="col"| VW
 +
! scope="col"| Honda
 +
! scope="col"| BMW
 +
|-
 +
| 19
 +
| 22
 +
| 30
 +
|}
 +
 +
Here '''v''' is a list of two values:
 +
 +
:<code>StepInterp(Years, Car_prices, [2007, 2008], Years) &rarr;</code>
 +
:{| class="wikitable"
 +
|-
 +
! scope="col"|
 +
! scope="col"| VW
 +
! scope="col"| Honda
 +
! scope="col"| BMW
 +
|-
 +
! scope="row"| 2007
 +
| 18K
 +
| 20K
 +
| 28K
 +
|-
 +
! scope="row"| 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».
 +
 +
=== {{Release||5.2|«leftLookup»}}{{Release|5.3||«use»}} ===
 +
 +
{{Release|5.3||
 +
(''new to [[Analytica 5.3]]'')
 +
The optional «use» parameter can be any one the following:
 +
* <code>'Left'</code>: Find the closest value in «xi» to the left of «x».
 +
* <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».
 +
}}
 +
 +
{{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».}}
 +
 +
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]]  
+
| [[Image:Stepinterp-graph.png|450px]]  
| [[Image:StepInterp2-graph.png]]
+
| [[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>
 
|}
 
|}
  
= See Also =
+
== See Also ==
 
 
 
* The User Group Webinar [[Analytica_User_Group/Past_Topics#Step_Interpolation|Intro to Step Interpolation]] recording.
 
* The User Group Webinar [[Analytica_User_Group/Past_Topics#Step_Interpolation|Intro to Step Interpolation]] recording.
 
* [[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.