Scientists and engineers often have to solve for the maximum or minimum of a multidimensional function, sometimes with constraints on the values of some or all of the variables. This is known as optimization, and is a rich, highly developed, and often difficult problem. Generally the problem is phrased as a minimization, which shows its kinship to the least-squares data fitting procedures discussed in a subsequent chapter. If a maximum is desired, one simply solves for the minimum of the negative of the function. The greatest difficulties typically arise if the multi-dimensional surface has local minima in addition to the global minimum, because there is no way to show that the minimum is local except by trial and error.