Difference between revisions of "CubicInterp"

Line 5: Line 5:
  
 
== CubicInterp(d, r, x, ''i'') ==
 
== CubicInterp(d, r, x, ''i'') ==
Returns the natural cubic spline interpolated values of «r» along «d», interpolating for values of «x».  The points ''(r,d)'' that get interpolated are indexed by «i». «d» and «r» must both be indexed by «i», and the values of «d» must be ascending. If «x» is less than the minimum value in «d», it returns the first value in «r»; if «x» is greater than the maximum value in «d», it returns the last value for «r».
+
Given coordinates «d» and «r», indexed by «i», it returns the y value corresponding to parameter «x», using cubic interpolation between the two values of «d» nearest to «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 have any dimensions. 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 largest (and last) value in «d» (x > d[@i=Size(i)]), it returns that largest value.
  
The index «i» is optional when «d» and «r» have only one index is common; however, it is recommended that you explicitly specify «i», since this will enable your expression to array-abstract if any dimension is ever added to «d» and «r» in the future.
+
Points having either «d» or «r» equal to [[Null]] are ignored.  When «x» is [[Null]], the result is [[Null]].
 
 
Points having either «d» or «r» equal to null are ignored.  When «x» is null, the result is null.
 
  
 
[[Image:Cubicinterp-graph.png]]
 
[[Image:Cubicinterp-graph.png]]
Line 16: Line 14:
  
 
==Example==
 
==Example==
Cubicinterp(Index_b, Array_a, 1.5, Index_b) →
+
The following example uses the [[Interpolation Example Variables]].
 +
 
 +
<code>Cubicinterp(Index_b, Array_a, 1.5, Index_b) →</code>
 
{| class="wikitable"
 
{| class="wikitable"
 
!! colspan="3" style="text-align: left;" | a &#9654;
 
!! colspan="3" style="text-align: left;" | a &#9654;
Line 28: Line 28:
 
| 2.219
 
| 2.219
 
|}
 
|}
 +
 +
== 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.
  
 
== History ==
 
== History ==

Revision as of 00:53, 30 October 2015


CubicInterp(d, r, x, i)

Given coordinates «d» and «r», indexed by «i», it returns the y value corresponding to parameter «x», using cubic interpolation between the two values of «d» nearest to «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 have any dimensions. 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 largest (and last) value in «d» (x > d[@i=Size(i)]), it returns that largest value.

Points having either «d» or «r» equal to Null are ignored. When «x» is Null, the result is Null.

Cubicinterp-graph.png

A cubic interpolation can vary wildly from the actual values of the data points. In the above graph, all the «r» values are positive, yet the interpolation is as small as -22.5 around x=33. Even if the «r» values are monotonically increasing, this does not mean that the cubic interpolation will be monotonically increasing. The MonoCubicInterp function is a variation that provides a guarantee of monotonicity.

Example

The following example uses the Interpolation Example Variables.

Cubicinterp(Index_b, Array_a, 1.5, Index_b) →

a ▶
a b c
0.6875 -2.875 2.219

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.

History

  • Analytica 4.1+
    • Null values allowed in «d» and «r».

See also

Comments


You are not allowed to post comments.