メインコンテンツ

addCustomTuning

R2026b

Add custom tuning parameter

Since R2026b

    Description

    Add-On Required: This feature requires the Optical Design and Simulation Library for Image Processing Toolbox add-on.

    compSet = addCustomTuning(compSet,fcnHandle,bound) adds a custom tuning parameter defined by fcnHandle to the optimization set compSet, with absolute bounds defined by bound. The tuning set, compSet, is an opticalOptimizationSet object. This function adds a CustomTuning object to the Tunings property of compSet and appends the details of the tuning parameter to the TuningTable property of compSet.

    compSet = addCustomTuning(compSet,fcnHandle,bound,arg1,...,argN) passes the additional input arguments arg1,...,argN to the custom tuning function.

    compSet = addCustomTuning(___,Name=name) specifies a name for the custom tuning parameter.

    Note

    This functionality requires Optimization Toolbox™.

    example

    Examples

    collapse all

    Import an optical system into the workspace.

    opsys = zmximport("CookeTriplet.zmx");

    Create an optical tolerance set with tolerance for the radius of curvature of surfaces.

    tolSet = opticalToleranceSet;
    tolSet = addSurfaceRadiusTolerance(tolSet,0.05);

    Create a merit function object for evaluating system performance.

    meritFcn = opticalMeritFunction;
    meritFcn = addSpot(meritFcn);

    Create an empty optical optimization set.

    compSet = opticalOptimizationSet;

    Add a custom tuning function to the optimization set. The custom function compensateAirGap is defined at the end of this example.

    compSet = addCustomTuning(compSet,@compensateAirGap,[-0.5 0.5],2,Name="Air Gap")
    compSet = 
      opticalOptimizationSet with properties:
    
            Tunings: [1×1 optics.optimize.CustomTuning]
        TuningTable: [1×3 table]
    
    

    Run a sensitivity analysis on the optical system using the merit function and tolerance, with the custom tuning function as the compensator.

    resultSensitivity = opticalSensitivity(opsys,meritFcn,tolSet,Compensator=compSet);

    Run a Monte Carlo tolerance analysis with 100 trials on the optical system using the same merit function, tolerance, and compensator settings.

    resultTolerance = opticalTolerance(opsys,meritFcn,tolSet,NumTrials=100,Compensator=compSet);

    Custom Function

    The compensateAirGap custom function adjusts the air gap between components in an optical system. The function gets the current gap after a given component, and then increases or decreases it according to the tuning parameter value.

    function [opsys,nominalAirGap] = compensateAirGap(opsys,tuningValue,componentIndex)
        nominalAirGap = distanceAfter(opsys,componentIndex);
        changeGap(opsys,componentIndex,nominalAirGap+tuningValue);
    end

    Input Arguments

    collapse all

    Optimization set to which to add the tuning parameters, specified as an opticalOptimizationSet object.

    Custom tuning function, specified as a function handle. The function must accept at least two input arguments: an opticalSystem object and a scalar tuning value. It must return exactly two output arguments: the modified opticalSystem object and the nominal scalar value.

    You can write the custom function in this format.

    function [newopsys,nominalValue] = myCustomFunction(opsys,tuningValue,arg1,..., argN)
        % add any supporting code here
    
        % define nominal value
        nominalValue = ...
    
        % return modified optical system
        newopsys = ...   
    end

    Data Types: function_handle

    Tuning bounds, specified as a 1-by-2 numeric vector of the form [min max] representing absolute bounds. Unlike built-in tuning parameters, custom tuning parameters do not support percentage bounds.

    Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

    Additional input arguments for the custom tuning function, specified as a comma-separated list. The types of the inputs depend on the function fcnHandle. These arguments are inputs to fcnHandle after the optical system and tuning parameter value arguments.

    Tuning parameter name, specified as a string scalar or character vector. Use this argument to identify the custom tuning parameter in the optimization set table.

    Data Types: char | string

    Output Arguments

    collapse all

    Updated optimization set, returned as an opticalOptimizationSet object with the custom tuning parameters appended. This function adds a CustomTuning object to the Tunings property of compSet and appends the details of the tuning parameter to the TuningTable property of compSet.

    Version History

    Introduced in R2026b