This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

fmincon Interior-Point Algorithm with Analytic Hessian

The fmincon interior-point algorithm can accept a Hessian function as an input. When you supply a Hessian, you may obtain a faster, more accurate solution to a constrained minimization problem.

The constraint set for this example is the intersection of the interior of two cones—one pointing up, and one pointing down. The constraint function c is a two-component vector, one component for each cone. Since this is a three-dimensional example, the gradient of the constraint c is a 3-by-2 matrix.

function [c ceq gradc gradceq] = twocone(x)
% This constraint is two cones, z > -10 + r
% and z < 3 - r

ceq = [];
r = sqrt(x(1)^2 + x(2)^2);
c = [-10+r-x(3);

if nargout > 2

    gradceq = [];
    gradc = [x(1)/r,x(1)/r;

The objective function grows rapidly negative as the x(1) coordinate becomes negative. Its gradient is a three-element vector.
function [f gradf] = bigtoleft(x)
% This is a simple function that grows rapidly negative
% as x(1) gets negative

if nargout > 1


Here is a plot of the problem. The shading represents the value of the objective function. You can see that the objective function is minimized near x = [-6.5,0,-3.5]:

 Code for generating the figure

The Hessian of the Lagrangian is given by the equation:


The following function computes the Hessian at a point x with Lagrange multiplier structure lambda:

function h = hessinterior(x,lambda)

h = [60*x(1)+2*x(3),2*x(2),2*x(1);
    2*x(1),2*x(2),0];% Hessian of f
r = sqrt(x(1)^2+x(2)^2);% radius
rinv3 = 1/r^3;
hessc = [(x(2))^2*rinv3,-x(1)*x(2)*rinv3,0;
    0,0,0];% Hessian of both c(1) and c(2)
h = h + lambda.ineqnonlin(1)*hessc + lambda.ineqnonlin(2)*hessc;

Run this problem using the interior-point algorithm in fmincon. To do this using the Optimization app:

  1. Set the problem as in the following figure.

  2. For iterative output, scroll to the bottom of the Options pane and select Level of display, iterative.

  3. In the Options pane, give the analytic Hessian function handle.

  4. Under Run solver and view results, click Start.

To perform the minimization at the command line:

  1. Set options as follows:

    options = optimoptions(@fmincon,'Algorithm','interior-point',...
  2. Run fmincon with starting point [–1,–1,–1], using the options structure:

    [x,fval,mflag,output] = fmincon(@bigtoleft,[-1,-1,-1],...

Examine the solution, objective function value, exit flag, and number of function evaluations and iterations:

x =

   -6.5000   -0.0000   -3.5000

fval =


mflag =


ans =


ans =


If you do not use a Hessian function, fmincon takes 9 iterations to converge, instead of 6:

options = optimoptions(@fmincon,'Algorithm','interior-point',...

[x fval mflag output]=fmincon(@bigtoleft,[-1,-1,-1],...


x =

   -6.5000   -0.0000   -3.5000

ans =


ans =

Both runs lead to similar solutions, but the F-count and number of iterations are lower when using an analytic Hessian.

Related Topics

Was this topic helpful?