Documentation

FunctionApproximation.Problem class

Package: FunctionApproximation

Object defining the function to approximate, or the lookup table to optimize

Description

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.

Construction

approximationProblem = FunctionApproximation.Problem() creates a FunctionApproximation.Problem object with default property values. When no function input is provided, the FunctionToApproximate property is set to 'sin'.

approximationProblem = FunctionApproximation.Problem(function) creates a FunctionApproximation.Problem object to approximate the function, Math Function block, or lookup table specified by function.

Input Arguments

expand all

Function 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 (MATLAB).

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

Properties

expand all

Function 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 (MATLAB).

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

Number 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

Desired 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)"];

Lower 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

Upper 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

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)";

Additional options and constraints to use in approximation, specified as a FunctionApproximation.Options object.

Methods

 solve Solve for optimized solution to function approximation problem

Copy Semantics

Handle. To learn how handle classes affect copy operations, see Copying Objects (MATLAB).

Examples

collapse all

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.

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.

Algorithms

expand all

Introduced in R2018a

Fixed-Point Designer Documentation Get trial now