Updated February 28, 2023
Introduction to Optimset Matlab
In Matlab, optimset is used to create or modify the parameter structure by optimizing options. These optimization options can be specified in an options structure that is created and it is used in various functions like fminsearch, fminbnd etc. Optimization Toolbox is one of the product developed by Mathworks where various optimization parameters are available that can be used with various Matlab functions. There are various parameters that can be mentioned in options structure like Display which will have various values or levels etc.
Working of Optimset in Matlab
In the structure can be created with the help of below syntaxes that can be used with various functions:
- options=optimset (Name argument, value argument): This is used when we want to specify the parameters with their respective values using name and value arguments. This will return an options structure.
- optimset (no input or output argument mentioned in the syntax): This will return or display all the parameters that are present with their respective values so it will be helpful for us to choose the required parameter for various requirements.
- options= optimset (no input argument mentioned): This syntax will create an options structure where all the parameters present inside will be set to .
- options=optimset(optimfun): This syntax is used to create an options structure with all the required parameters and their respective default values which are relevant to the function mentioned in the syntax i.e. optimfun.
- options=optimset (oldoptns, Name argument, value argument): This syntax is used to create an option structure which is meant to create a copy of the argument oldoptns and changes the required parameters with the help of name and value arguments mentioned in the syntax.
- options=optimset (oldoptns, newoptns): This syntax is used when we want to combine oldoptns and newoptns and the parameters that are not empty in newoptns structure will overwrite the parameters present in oldoptns structure.
The input and output arguments mentioned in the above syntaxes have certain criteria that has been followed. The input argument ‘optimfun’ is an optimization solver which can be specified in the form of function handle or function name. The datatypes that are accepted by the input argument are char, string and function handle. Oldoptns and newoptns are the other two input arguments which should be in the form of structure. Name and value pair arguments are the arguments which are mentioned with the parameter and their respective value. We can specify number of name and value pair arguments in the syntax, name argument should be enclosed with quotes.
There are various parameters that can be mentioned in the syntax with their respective values like:
- Display Option: This is used to decide various levels of display which have various values like:
- Notify: This value is mentioned when we want to display the output if the mentioned function does not converge.
- Final: This value is used to when we want to display the final output in the end of the whole algorithm process.
- Off/None: These values are used when we do not display any output for the process.
- Iter: This value is used when we want to display the output in each iteration in the whole process.
The data types that are accepted are in the form of char or string.
- FunValCheck Option: This option is used to check whether the required function values are valid or not. This is the name argument which has two values off or on and they are separated by comma. If the value is on, then the values returned by objective function may be in the form of complex or NaN. The data types that are accepted are in the form of char or string.
- MaxFunEvals Option: This option is used when we want to specify the maximum number of evaluations in the respective algorithm. The required parameter and its value is separated by comma. The value of the mentioned parameter is in the form of positive integer. This option is available for only two Matlab functions that are fminbnd and fminsearch. The default value for fminbnd function is 500 and the default value for fminsearch is 200 multiplied by number of variables. The datatypes that are accepted are in the form of single or double.
- MaxIter Option: This option is used when we want to specify the maximum number of iterations in the respective algorithm. The required parameter and its value is separated by comma. The value of the mentioned parameter is in the form of positive integer. This option is available for only two Matlab functions that are fminbnd and fminsearch. The default value for fminbnd function is 500 and the default value for fminsearch is 200 multiplied by number of variables. The datatypes that are accepted are in the form of single or double.
- OutputFcn Option: This is the output function which can be specified in the form of  (default), function name, function handle or array of function handles. This output function runs after every iteration which will help us to track the progress of the respective algorithm. This parameter is available for Matlab functions like fminbnd, fminsearch and fzero. The datatypes that can be accepted are in the form of char, string, cell and function_handle.
Examples to understand the use of Optimset in Matlab
Below are the examples mentioned:
To create default options for fminsearch solver:
options = optimset('fminsearch');
tol1 = options.TolX
To define a tolerance level of 1e-4 and display it:
oldopts = optimset('TolFun',1e-4);
options = optimset(oldopts,'TolX',1e-4);
oldopts = optimset('TolFun',1e-4);
options = optimset(oldopts,'TolX',1e-2);
There are various parameters associated with optimset in Matlab which should also be learnt while working with it. There are certain limitations which should be taken care of, one of them is optimset in Matlab works only with four function solvers that are fminbnd, fminsearch, fzero and lsqnonneg. If we want to set other options, then it is advisable to use optimoptions instead.
This is a guide to Optimset Matlab. Here we discuss an introduction to Optimset Matlab, along with appropriate syntax, working and respective examples. You can also go through our other related articles to learn more –