Methods for Approximating Function Values
About Approximating Function Values
The second stage of a table lookup operation involves generating outputs that correspond to the supplied inputs. If the inputs match the values of indices specified in breakpoint data sets, the block outputs the corresponding values. However, if the inputs fail to match index values in the breakpoint data sets, Simulink^{®} estimates the output. In the block parameter dialog box, you can specify how to compute the output in this situation. The available lookup methods are described in the following sections.
Interpolation Methods
When an input falls between breakpoint values, the block interpolates the output value using neighboring breakpoints. Most lookup table blocks have the following interpolation methods available:
Flat
— Disables interpolation and uses the rounding operation titledUse Input Below
. For more information, see Rounding Methods.Nearest
— Disables interpolation and returns the table value corresponding to the breakpoint closest to the input. If the input is equidistant from two adjacent breakpoints, the breakpoint with the higher index is chosen.Linear pointslope
— Fits a line between the adjacent breakpoints, and returns the point on that line corresponding to the input. This is the equation for linear pointslope, where x is the input data, y is the output table data (x_{i},y_{i} is the coordinate of the table data), and f is the fraction. For more information on x_{i},y_{i}, see About Lookup Table Blocks.$$f=\frac{x{x}_{i}}{{x}_{i+1}{x}_{i}}$$
$$y={y}_{i}+f({y}_{i+1}{y}_{i})$$
Cubic spline
— Fits a cubic spline to the adjacent breakpoints, and returns the point on that spline corresponding to the input.Linear Lagrange
— Fits a line between the adjacent breakpoints using firstorder Lagrange interpolation, and returns the point on that line corresponding to the input. This is the equation for linear Lagrange, where x is the input data, y is the output table data, and f is the fraction. f is constrained to range from 0 to less than 1 ([0,1)
). For more information on x and y, see About Lookup Table Blocks.$$f=\frac{x{x}_{i}}{{x}_{i+1}{x}_{i}}$$
$$y=(1f){y}_{i}+f{y}_{i+1}$$
If the extrapolation method is
Linear
, the extrapolation value is calculated based on the selected linear interpolation method. For example, if the interpolation method is Linear Lagrange, the extrapolation method inherits the Linear Lagrange equation to compute the extrapolated value.Akima spline
— Fits an Akima spline to the adjacent breakpoints, and returns the point on that spline corresponding to the input. The interpolation method works only with theAkima spline
extrapolation method. The modified Akima cubic Hermite interpolation method has these properties:It produces fewer undulations than Cubic spline.
It is more efficient for realtime applications than Cubic spline.
Unlike Cubic spline, it does not produce overshoots.
Unlike Cubic spline, it supports nonscalar signals.
Note
The Lookup Table Dynamic block does not let you select an
interpolation method. The InterpolationExtrapolation
option in the Lookup Method field of the block parameter
dialog box performs linear interpolation.
Each interpolation method includes a tradeoff between computation time and the smoothness of the result. Although rounding is quickest, it is the least smooth. Linear interpolation is slower than rounding but generates smoother results, except at breakpoints where the slope changes. Cubic spline interpolation is the slowest method but produces smooth results. Akima spline produces the smoothest results.
Extrapolation Methods
When an input falls outside the range of a breakpoint data set, the block extrapolates the output value from a pair of values at the end of the breakpoint data set. Most lookup table blocks have the following extrapolation methods available:
Clip
— Disables extrapolation and returns the table data corresponding to the end of the breakpoint data set range. This does not provide protection against outofrange values.Linear
— If the interpolation method isLinear
, this extrapolation method fits a line between the first or last pair of breakpoints, depending on whether the input is less than the first or greater than the last breakpoint. If the interpolation method isCubic spline
orAkima spline
, this extrapolation method fits a linear surface using the slope of the interpolation at the first or last break point, depending on whether the input is less than the first or greater than the last breakpoint. The extrapolation method returns the point on the generated linear surface corresponding to the input.If the extrapolation method is
Linear
, the extrapolation value is calculated based on the selected linear interpolation method. For example, if the interpolation method is Linear Lagrange, the extrapolation method inherits the Linear Lagrange equation to compute the extrapolated value.Cubic spline
— Fits a cubic spline to the first or last pair of breakpoints, depending if the input is less than the first or greater than the last breakpoint, respectively. This method returns the point on that spline corresponding to the input.Akima spline
— Fits an Akima spline to the first or last pair of breakpoints, depending if the input is less than the first or greater than the last breakpoint, respectively. This method returns the point on that spline corresponding to the input.
Note
The Lookup Table Dynamic block does not let you select an
extrapolation method. The InterpolationExtrapolation
option in the Lookup Method field of the block parameter
dialog box performs linear extrapolation.
In addition to these methods, some lookup table blocks, such as the nD Lookup Table block, allow you to select an action to perform when encountering situations that require extrapolation. For instance, you can specify that Simulink generate either a warning or an error when the lookup table inputs are outside the ranges of the breakpoint data sets. To specify such an action, select it from the Diagnostic for outofrange input list on the block parameter dialog box.
Rounding Methods
If an input falls between breakpoint values or outside the range of a breakpoint data set and you do not specify interpolation or extrapolation, the block rounds the value to an adjacent breakpoint and returns the corresponding output value. For example, the Lookup Table Dynamic block lets you select one of the following rounding methods:
Use Input Nearest
— Returns the output value corresponding to the nearest input value.Use Input Below
— Returns the output value corresponding to the breakpoint value that is immediately less than the input value. If no breakpoint value exists below the input value, it returns the breakpoint value nearest the input value.Use Input Above
— Returns the output value corresponding to the breakpoint value that is immediately greater than the input value. If no breakpoint value exists above the input value, it returns the breakpoint value nearest the input value.
Example Output for Lookup Methods
In the following model, the Lookup Table Dynamic block accepts
a vector of breakpoint data given by [5:5]
and a vector of table
data given by sinh([5:5])
.
The Lookup Table Dynamic block outputs the following values when using the specified lookup methods and inputs.
Lookup Method  Input  Output  Comment 



 N/A 

 N/A  


 N/A 

 The block uses the value for
 


 The block uses the value for


 The block uses the value for
 


 The block uses the value for


 The block uses the value for
 


 The block uses the value for
