title: Violation nonlinear constraints fmincon interior-point Matlab
body: <p>I am trying to impose two nonlinear constraints with <code>fmincon (interior-point)</code> in Matlab:</p>
  
  <pre><code>sqrt(w*S*w') &lt;= sigmaTgt/sqrt(260)
  sqrt(w*S*w') &gt;= sigmaTgt/sqrt(260)-0.02/sqrt(260)
  </code></pre>
  
  <p>I tried the following:</p>
  
  <pre><code>function [c,ceq] = in_nonlconstr(w, S)
  
      c(1) = sqrt(w*S*w') - tgtVolAnn/sqrt(260);
      c(2) = - sqrt(w*S*w') + ( tgtVolAnn/sqrt(260) - 0.02/sqrt(260) );
      ceq = [];
  
  end
  </code></pre>
  
  <p>but after the optimization I keep getting that <code>sqrt(w*S*w')</code> satisfies <code>c(1)</code> but not <code>c(2)</code>, despite an <code>exitflag</code> of 1 and the solver having converged.</p>
  
  <p>Am I writing it correctly or is there smth wrong with my solver?</p>
  
  <hr>
  
  <p>Message from <code>output.message</code>:</p>
  
  <blockquote>
    <p>Local minimum found that satisfies the constraints.</p>
    
    <p>Optimization completed because the objective function is
    non-decreasing in  feasible directions, to within the default value of
    the optimality tolerance, and constraints are satisfied to within the
    default value of the constraint tolerance.</p>
    
    <p>Stopping criteria details:</p>
    
    <p>Optimization completed: The relative first-order optimality measure,
    9.821943e-07, is less than options.OptimalityTolerance = 1.000000e-06, and the relative maximum constraint violation, 0.000000e+00, is less
    than options.ConstraintTolerance = 1.000000e-06.</p>
    
    <p>Optimization Metric                                            Options
    relative first-order optimality =   9.82e-07       OptimalityTolerance
    =   1e-06 (default) relative max(constraint violation) =   0.00e+00    ConstraintTolerance =   1e-06 (default)</p>
  </blockquote>