Contenido principal

approximate

R2026b

Class: FunctionApproximation.LUTSolution
Namespace: FunctionApproximation

Generate Lookup Table block or lookup table as MATLAB function from FunctionApproximation.LUTSolution

Description

approximate(solution) generates a lookup table approximation from a FunctionApproximation.LUTSolution object. The output depends on the ApproximateSolutionType property of the associated FunctionApproximation.Options object.

  • If ApproximateSolutionType property is set to 'MATLAB', this syntax creates one MATLAB® function file for each lookup table in solution.

  • If ApproximateSolutionType is set to 'Simulink', approximate, this syntax creates a Simulink® model containing a subsystem with a Lookup Table block surrounded by Data Type Conversion blocks. If solution contains multiple lookup tables, the model uses a shared prelookup stage with separate interpolation stages for each table.

example

approximate(solution,'Name',fileName) generates a lookup table as a MATLAB function with the name of the generated .m script specified by fileName. This syntax applies only when the ApproximateSolutionType property of FunctionApproximation.Options is set to MATLAB.

approximate(solution,'Name',fileName,'Path',filePath) generates a lookup table as a MATLAB function with the file path for the generated .m script specified by filePath. This syntax applies only when the ApproximateSolutionType property of FunctionApproximation.Options is set to MATLAB.

Input Arguments

expand all

The solution to generate a lookup table from, specified as a FunctionApproximation.LUTSolution object.

File name for generated MATLAB function, specified as a character array. If you do not specify a custom file name, the function uses a timestamp to generate a unique filename, for example, approximateFunction_20210617T111033122.m.

For solutions that generate multiple lookup tables, specify a cell array of string or character vectors with one filename per lookup table. The number of names must match the number of lookup tables in the solution.

Example: approximate(solution,'Name','myLUT')

Example: approximate(solution, "Name", ["lut1","lut2"])

Data Types: char | cell

File path for generated MATLAB function, specified as a character array. If no custom file path name is specified, the current working folder is used.

Example: approximate(solution,'Name','myLUT','Path','C:\Users\myPath')

Data Types: char

Examples

expand all

Create a FunctionApproximation.Problem object defining the function you want to approximate.

problem = FunctionApproximation.Problem('tanh')
problem = 

  1×1 FunctionApproximation.Problem with properties:

    FunctionToApproximate: @(x)tanh(x)
           NumberOfInputs: 1
          NumberOfOutputs: 1
               InputTypes: "numerictype(1,16,12)"
         InputLowerBounds: -8
         InputUpperBounds: 8
               OutputType: "numerictype(1,16,15)"
                  Options: [1×1 FunctionApproximation.Options]

Use default values for all other options. Approximate the tanh function using the solve method.

solution = solve(problem)
Searching for fixed-point solutions.

|  ID |  Memory (bits) | Feasible | Table Size | Breakpoints WLs | TableData WL | BreakpointSpecification |             Error(Max,Current) | 
|   0 |             64 |        0 |          2 |              16 |           16 |             EvenSpacing |     7.812500e-03, 7.229091e-01 |
|   1 |           1248 |        1 |         76 |              16 |           16 |             EvenSpacing |     7.812500e-03, 4.368265e-03 |
|   2 |           1232 |        1 |         75 |              16 |           16 |             EvenSpacing |     7.812500e-03, 4.439035e-03 |
|   3 |            944 |        1 |         57 |              16 |           16 |             EvenSpacing |     7.812500e-03, 7.780470e-03 |
|   4 |            928 |        1 |         56 |              16 |           16 |             EvenSpacing |     7.812500e-03, 5.383741e-03 |
|   5 |            656 |        0 |         39 |              16 |           16 |             EvenSpacing |     7.812500e-03, 1.678519e-02 |
|   6 |            640 |        0 |         38 |              16 |           16 |             EvenSpacing |     7.812500e-03, 1.660649e-02 |
|   7 |            784 |        1 |         47 |              16 |           16 |             EvenSpacing |     7.812500e-03, 7.743777e-03 |
|   8 |            704 |        1 |         42 |              16 |           16 |             EvenSpacing |     7.812500e-03, 7.805676e-03 |
|   9 |            672 |        1 |         40 |              16 |           16 |             EvenSpacing |     7.812500e-03, 7.809550e-03 |
|  10 |            368 |        0 |         21 |              16 |           16 |             EvenSpacing |     7.812500e-03, 4.855583e-02 |
|  11 |            512 |        0 |         30 |              16 |           16 |             EvenSpacing |     7.812500e-03, 2.773526e-02 |
|  12 |            592 |        0 |         35 |              16 |           16 |             EvenSpacing |     7.812500e-03, 2.088471e-02 |
|  13 |            624 |        0 |         37 |              16 |           16 |             EvenSpacing |     7.812500e-03, 1.870074e-02 |
|  14 |            384 |        1 |         12 |              16 |           16 |          ExplicitValues |     7.812500e-03, 7.812317e-03 |
|  15 |            384 |        0 |         12 |              16 |           16 |          ExplicitValues |     7.812500e-03, 1.196141e-02 |
|  16 |            384 |        1 |         12 |              16 |           16 |          ExplicitValues |     7.812500e-03, 7.812317e-03 |

Best Solution
|  ID |  Memory (bits) | Feasible | Table Size | Breakpoints WLs | TableData WL | BreakpointSpecification |             Error(Max,Current) |
|  14 |            384 |        1 |         12 |              16 |           16 |          ExplicitValues |     7.812500e-03, 7.812317e-03 |


solution = 

  1×1 FunctionApproximation.LUTSolution with properties:

          ID: 14
    Feasible: "true"

Generate a Simulink® subsystem containing a Lookup Table block approximating the tanh function.

approximate(solution)

Use the example Approximate Multiple Math Functions to generate a FunctionApproximation.LUTSolution object that contains two lookup table approximations, multiFunctionSolution. Generate a Simulink subsystem that contains a Lookup Table block for each function.

approximate(multiFunctionSolution)

A model is shown with two outputs from the approximation block

The generated subsystem has two outputs, one for each Lookup Table block in the FunctionApproximation.LUTSolution object.

Version History

Introduced in R2018a