Optimization Toolbox    

Optimization of Inline Objects Instead of M-Files

The routines in the Optimization Toolbox also perform optimization on inline objects, avoiding the need to write M-files to define functions.

To represent a mathematical function at the command line, create an inline object from a string expression. For example, you can create an inline object of the humps function (use the command type humps to see the M-file function humps.m):

You can then evaluate f at 2.0:

And you can pass f to an optimization routine to minimize it:

You can also create functions of more than one argument with inline by specifying the names of the input arguments along with the string expression. For example, to use lsqcurvefit, you first need a function that takes two input arguments, x and xdata,

and you then call lsqcurvefit.

Other examples that use this technique:


  Output Headings: Large-Scale Algorithms Typical Problems and How to Deal with Them