Package: FunctionApproximation
Object defining the function to approximate, or the lookup table to optimize
The FunctionApproximation.Problem
object defines the function to
approximate with a lookup table, or the lookup table block to optimize. After defining
the problem, use the solve
method to generate a FunctionApproximation.LUTSolution
object that contains the
approximation.
creates a approximationProblem
= FunctionApproximation.Problem()FunctionApproximation.Problem
object with default property
values. When no function
input is provided, the
FunctionToApproximate
property is set to
'sin'
.
creates a approximationProblem
= FunctionApproximation.Problem(function
)FunctionApproximation.Problem
object to approximate the
function, Math Function block, or lookup table specified by
function
.
function
— Function or block to approximate, or lookup table block to
optimize'sin'
(default) | math function | function handle | Math Function block | Lookup Table block | Subsystem blockFunction or block to approximate, or the lookup table block to optimize, specified as a function handle, a math function, a Simulink® block or subsystem, or one of the lookup table blocks (for example, 1-D Lookup Table, n-D Lookup Table).
If you specify one of the lookup table blocks, the solve
method generates an optimized lookup table.
If you specify a math function, a function handle, or a block, the
solve
method generates a lookup table
approximation of the input function.
Function handles must be on the MATLAB® search path, or approximation fails.
The MATLAB math functions supported for approximation are:
1./x
10.^x
2.^x
acos
acosh
asin
asinh
atan
atan2
atanh
cos
cosh
exp
log
log10
log2
sin
sinh
sqrt
tan
tanh
x.^2
Note
Functions and function handles that you approximate must be vectorized, meaning that for each input, there is exactly one output. For more information, see Vectorization.
Tip
The process of generating a lookup table approximation is faster for a function handle than for a subsystem. If a subsystem can be represented by a function handle, it is faster to approximate the function handle.
Data Types: char
| function_handle
FunctionToApproximate
— Function to approximate, or lookup table block to optimize'sin'
(default) | math function | function handle | Math Function block | Lookup Table block | Subsystem blockFunction or block to approximate, or the lookup table block to optimize, specified as a function handle, a math function, a Simulink block or subsystem, or one of the lookup table blocks (for example, 1-D Lookup Table, n-D Lookup Table).
If you specify one of the lookup table blocks, the solve
method generates an optimized lookup table.
If you specify a math function, a function handle, or a block, the
solve
method generates a lookup table approximation
of the input function.
Function handles must be on the MATLAB search path, or approximation fails.
The MATLAB math functions supported for approximation are:
1./x
10.^x
2.^x
acos
acosh
asin
asinh
atan
atan2
atanh
cos
cosh
exp
log
log10
log2
sin
sinh
sqrt
tan
tanh
x.^2
Note
Functions and function handles that you approximate must be vectorized, meaning that for each input, there is exactly one output. For more information, see Vectorization.
Tip
The process of generating a lookup table approximation is faster for a function handle than for a subsystem. If a subsystem can be represented by a function handle, it is faster to approximate the function handle.
Data Types: char
| function_handle
NumberOfInputs
— Number of inputs to function approximationNumber of inputs to approximated function. This property is inferred from
the FunctionToApproximate
property, therefore it is not
a writable property.
If you are generating a Direct Lookup Table, the function to approximate can have no more than two inputs.
Data Types: double
InputTypes
— Desired data types of inputs to function approximationnumerictype
object | vector of numerictype
objects | Simulink.Numerictype
object | vector of Simulink.Numerictype
objectsDesired data types of the inputs to the approximated function, specified
as a numerictype
,
Simulink.Numerictype
, or a vector of
numerictype
or
Simulink.Numerictype
objects. The number of
InputTypes
specified must match the
NumberOfInputs
.
Example: problem.InputTypes = ["numerictype(1,16,13)",
"numerictype(1,16,10)"];
InputLowerBounds
— Lower limit of range of inputs to function to approximateLower limit of range of inputs to function to approximate, specified as a
scalar or vector. If you specify inf
, the
InputLowerBounds
used during the approximation is
derived from the InputTypes
property. The dimensions of
InputLowerBounds
must match the
NumberOfInputs
.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| fi
InputUpperBounds
— Upper limit of range of inputs to function to approximateUpper limit of range of inputs to function to approximate, specified as a
scalar or vector. If you specify inf
, the
InputUpperBounds
used during the approximation is
derived from the InputTypes
property. The dimensions of
InputUpperBounds
must match the
NumberOfInputs
.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| fi
OutputType
— Desired data type of the function approximation outputnumerictype
| Simulink.Numerictype
Desired data type of the function approximation output, specified as a
numerictype
or
Simulink.Numerictype
. For example, to specify that
you want the output to be a signed fixed-point data type with 16-bit word
length and best-precision fraction length, set the
OutputType
property to
"numerictype(1,16)"
.
Example: problem.OutputType =
"numerictype(1,16)";
Options
— Additional options and constraints to use in approximationFunctionApproximation.Options
objectAdditional options and constraints to use in approximation, specified as a
FunctionApproximation.Options
object.
solve | Solve for optimized solution to function approximation problem |
Handle. To learn how handle classes affect copy operations, see Copying Objects.
Create a FunctionApproximation.Problem
object, specifying a function handle that you want to approximate.
problem = FunctionApproximation.Problem(@(x,y) sin(x)+cos(y))
problem = FunctionApproximation.Problem with properties FunctionToApproximate: @(x,y)sin(x)+cos(y) NumberOfInputs: 2 InputTypes: ["numerictype('double')" "numerictype('double')"] InputLowerBounds: [-Inf -Inf] InputUpperBounds: [Inf Inf] OutputType: "numerictype('double')" Options: [1×1 FunctionApproximation.Options]
The FunctionApproximation.Problem
object,
problem, uses default property values.
Set the range of the function inputs to be between zero and
2*pi
.
problem.InputLowerBounds = [0,0]; problem.InputUpperBounds = [2*pi, 2*pi]
problem = FunctionApproximation.Problem with properties FunctionToApproximate: @(x,y)sin(x)+cos(y) NumberOfInputs: 2 InputTypes: ["numerictype('double')" "numerictype('double')"] InputLowerBounds: [0 0] InputUpperBounds: [6.2832 6.2832] OutputType: "numerictype('double')" Options: [1×1 FunctionApproximation.Options]
Create a FunctionApproximation.Problem
object, specifying a math function to approximate.
problem = FunctionApproximation.Problem('log')
problem = FunctionApproximation.Problem with properties FunctionToApproximate: @(x)log(x) NumberOfInputs: 1 InputTypes: "numerictype(1,16,10)" InputLowerBounds: 0.6250 InputUpperBounds: 15.6250 OutputType: "numerictype(1,16,13)" Options: [1×1 FunctionApproximation.Options]
The math functions have appropriate input range, input data type, and output data type property defaults.
Create a FunctionApproximation.Problem
object to optimize an existing lookup table.
load_system('sldemo_fuelsys'); problem = FunctionApproximation.Problem('sldemo_fuelsys/fuel_rate_control/airflow_calc/Pumping Constant')
problem = FunctionApproximation.Problem with properties FunctionToApproximate: 'sldemo_fuelsys/fuel_rate_control/airflow_calc/Pumping Constant' NumberOfInputs: 2 InputTypes: ["numerictype('single')" "numerictype('single')"] InputLowerBounds: [50 0.0500] InputUpperBounds: [1000 0.9500] OutputType: "numerictype('single')" Options: [1×1 FunctionApproximation.Options]
The software infers the properties of the Problem
object from the model.
Functions and function handles that you approximate must meet the following criteria.
The function must be time-invariant.
The function must operate element-wise, meaning for each input there is one output.
The function must not contain states.
For more information, see Vectorization.
When a Problem
object specifies infinite input ranges and the
input type is non-floating-point, during the approximation, the software infers
upper and lower ranges based on the range of the input data type. The resulting
FunctionApproximation.LUTSolution
object specifies the bounds that the
algorithm used during the approximation, not the originally specified infinite
bounds.
If the InputLowerBounds
or
InputUpperBounds
specified for a Problem
object fall outside the range of the specified InputTypes
, the
algorithm uses the range of the data type specified by
InputTypes
for the approximation.
In cases where the BreakpointSpecification
property of the
FunctionApproximation.Options
object is set to
'EvenSpacing'
, but the InputUpperBounds
or InputLowerBounds
property of the FunctionApproximation.Problem
object is equal to the range of the
InputTypes
, the algorithm does not attempt to find a
solution using 'EvenPow2Spacing'
.
FunctionApproximation.LUTMemoryUsageCalculator
| FunctionApproximation.LUTSolution
| FunctionApproximation.Options
approximate
| compare
| solve