# Optimization

MC Grating's built-in multidimensional optimization: the Davidon–Fletcher–Powell quasi-Newton method, almost any incident-wave or structure parameter as a variable, a criterion function built from independent points on efficiencies or resonance positions, and step-by-step examples.

Canonical: https://mcgrating.com/features/optimization.html


A quasi-Newton optimizer built into every Full-edition code, with the criterion function and the variables chosen in two dialog pages.

## The method

The multidimensional optimization method is based on the approach suggested by Davidon (1959), and further developed by Fletcher and Powell. The Davidon–Fletcher–Powell method [[14](https://mcgrating.com/references.html#ref-14)] is a Quasi-Newton Method also known as a Variable Metrics Method. Almost every incident wave, and structure parameters, including refractive indexes, can be set as variables. There isn't any restriction on optimization search area except a physical meaning of the variable parameters (for example a layer thickness can not be negative).

In the ideal case of parabolic behaviour of the criterion function, the process converges after N iterations for N variables; in many real cases it takes more, and after the defined number of iterations the code continues from the position reached in the direction of steepest descent. The [Optimization page](https://mcgrating.com/docs/common/optimization.html) sets the iterations, the accuracy of the numerical derivatives and the size of the region searched.

## The criterion function

The objective is the minimum mean-square deviation between user-defined target values and the calculated ones. The [Criterion Function](https://mcgrating.com/docs/common/criterion.html) is a set of completely independent criterion points, each targeting the power of a given diffraction order — or, in the collinear codes, the angular position of a resonance of the structure — at its own wavelength, angle and polarization, with a weight. Several methods of a criterion function construction allow solving variety of design and inverse structure reconstruction problems.

## The variables

The [Variable Parameters](https://mcgrating.com/docs/common/variable.html) page selects what varies: wavelength, period and angles, and the structure parameters exported from the Settings dialog; media with identical refractive indices can be grouped so that one variable moves them together. Optimization is available in all six Full-edition codes; the [Optimization dialog](https://mcgrating.com/docs/common/optimization-dialog.html) topic describes the controls.

## Examples

- The rear mirror of a [914 nm Nd:YVO4 microlaser](https://mcgrating.com/publications/sychugov-2000-914nm-microlaser.html): transparent at the 808 nm pump, reflecting at 914 nm; step-by-step example [4.2](https://mcgrating.com/docs/examples.html#ex-4-2).
- Step-by-step example [1.1.2](https://mcgrating.com/docs/examples.html#ex-1-1-2) and its neighbours use the Optimize button on resonant waveguide gratings.

Optimization is a Full-edition feature. In demo mode refractive indices, being fixed at multiples of 0.5, cannot be variables.
