

The constraint vector c is a row vector, and the gradient of c(i) is represented in the ith column of the matrix gradc. For a problem-based approach to this problem using automatic differentiation, see Constrained Electrostatic Nonlinear Optimization, Problem-Based.Ĭ = (x(3*i-2).^2 + x(3*i-1).^2 + (x(3*i)+1).^2 - 1).' Problem-based optimization can calculate and use gradients automatically see Automatic Differentiation in Optimization Toolbox. So, you need to take several steps to symbolically generate the objective function, constraints, and all their requisite derivatives, in a form suitable for the interior-point algorithm of fmincon. In particular, symbolic variables are real or complex scalars, whereas Optimization Toolbox functions pass vector arguments. Symbolic Math Toolbox functions have different syntaxes and structures compared to Optimization Toolbox™ functions. This example shows how to use matlabFunction to generate files that evaluate the objective and constraint functions and their derivatives at arbitrary points. MatlabFunction (Symbolic Math Toolbox) generates either an anonymous function or a file that calculates the values of a symbolic expression. This example shows how to use jacobian to generate symbolic gradients and Hessians of objective and constraint functions. So, for example, you can obtain the Hessian matrix (the second derivatives of the objective function) by applying jacobian to the gradient. Jacobian (Symbolic Math Toolbox) generates the gradient of a scalar function, and generates a matrix of the partial derivatives of a vector function.
