Difference between revisions of "Interpolation functions"

Line 25: Line 25:
 
|}
 
|}
  
Array_a:
+
<code>Array_a:</code>
 
{| class="wikitable"
 
{| class="wikitable"
 
!
 
!
Line 37: Line 37:
 
!a
 
!a
 
|7
 
|7
|-3
+
| -3
 
|1
 
|1
 
|-
 
|-
 
!b
 
!b
|-4
+
| -4
|-1
+
| -1
 
|6
 
|6
 
|-
 
|-
Line 48: Line 48:
 
|5
 
|5
 
|0
 
|0
|-2
+
| -2
 
|}
 
|}
 +
 +
==Stepinterp(x, y, v, i)==
 +
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 <code>Car_prices</code> corresponding to <code>Years >= 2007.5</code>:
 +
 +
<code>Stepinterp(Years, Car_prices, 2007.5, Years) &rarr;</code>
 +
{| class="wikitable""
 +
! VW
 +
! Honda
 +
! BMW
 +
|-
 +
| 19K
 +
| 22K
 +
| 30K
 +
|}
 +
 +
Here '''v''' is a list of two values:
 +
 +
<code>Stepinterp(Years, Car_prices, [2007, 2008], Years) &rarr;</code>
 +
{| class="wikitable""
 +
! VW
 +
! Honda
 +
! BMW
 +
|-
 +
! 2007
 +
| 18K
 +
| 20K
 +
| 28K
 +
|-
 +
! 2008
 +
| 19K
 +
| 22K
 +
| 30K
 +
|}
 +
 +
  
 
==See Also==
 
==See Also==
 
<footer>Relational tables and multiD arrays / {{PAGENAME}} / Fourier Transform</footer>
 
<footer>Relational tables and multiD arrays / {{PAGENAME}} / Fourier Transform</footer>

Revision as of 00:11, 13 December 2015

These three functions interpolate across arrays. Given arrays y and x with a common index i, these functions interpolate a value for y corresponding to value v along the x axis.

Chapter12 3.png

LinearInterp() and CubicInterp() use these variables:

Index_a:

a b c

Index_b:

1 2 3

Array_a:

Index_b ▶
Index_a: ▼ 1 2 3
a 7 -3 1
b -4 -1 6
c 5 0 -2

Stepinterp(x, y, v, i)

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 Car_prices corresponding to Years >= 2007.5:

Stepinterp(Years, Car_prices, 2007.5, Years) →

VW Honda BMW
19K 22K 30K

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


See Also

Comments


You are not allowed to post comments.