title: Why does MATLAB fmincon ignore non-linear constraints?
body: <p>I want to use MATLABs fmincon function to solve a non-linear problem of which I know that it can be solved in a different way very easily but I want to use fmincon (you might not need the following detailed information about the problem but I provided them in case you need):</p>
  
  <p>Function f(x) is a quadratic function with its vertex at point (5|1).</p>
  
  <p><code>f(x)=0.1(x-5)^2+1    for   0&lt;=x&lt;=5</code></p>
  
  <p>Function g(x) is a polynom of order 4 with its vertex at Point (c|0).</p>
  
  <p><code>g(x)=(x-c)^4         for   0&lt;=x&lt;=c</code></p>
  
  <p>Function h is just a line on the x axis.</p>
  
  <p><code>h=0                  for   c&lt;=x&lt;=5</code></p>
  
  <p><a href="https://i.stack.imgur.com/f6Nb1.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/f6Nb1.jpg" alt="image of the graphs"></a></p>
  
  <p>I want to minimize the Area between the function f(x) and the two connected functions g(x) and h, in the interval [0,5]</p>
  
  <p><code>minimize A=2*(int(f,[0,5])-int(g,[0,c]))=55/3 - (2*c^5)/5</code></p>
  
  <p>Also I have the constraint that f(x) must always be 1 unit above the functions g(x) and h.</p>
  
  <p>From the graph I know that the variable c must be between 0 and 2 (just a range for the fmincon function).</p>
  
  <p>This is my .m file:</p>
  
  <pre><code>clc
  clear
  
  format long;
  options = optimoptions(@fmincon, 'Display', 'iter', 'Algorithm', 'interior-point');
  
  fun=@(x)55/3 - (2*(x(1))^5)/5;
  
  lb = [0];
  ub = [2];
  
  [x,fval] = fmincon(fun,[0.1],[],[],[],[],lb,ub,@cons_Q6,options)
  </code></pre>
  
  <p>The constraints file looks like this (I inserted a lot of values for x with an increment of 0.1):</p>
  
  <pre><code>function [c,ceq]=cons_Q6(x)
  c=[(0.0-x(1))^4-0.1*(0.0-5)^2
  (0.1-x(1))^4-0.1*(0.1-5)^2
  (0.2-x(1))^4-0.1*(0.2-5)^2
  (0.3-x(1))^4-0.1*(0.3-5)^2
  (0.4-x(1))^4-0.1*(0.4-5)^2
  (0.5-x(1))^4-0.1*(0.5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.3-5)^2
  (4.4-x(1))^4-0.1*(4.4-5)^2
  (4.5-x(1))^4-0.1*(4.5-5)^2
  (4.6-x(1))^4-0.1*(4.6-5)^2
  (4.7-x(1))^4-0.1*(4.7-5)^2
  (4.8-x(1))^4-0.1*(4.8-5)^2
  (4.9-x(1))^4-0.1*(4.9-5)^2
  (5.0-x(1))^4-0.1*(5.0-5)^2
  ];
  ceq=[];
  </code></pre>
  
  <p>As you can see, I've set the bounds for the unknown variable so that <code>x(1)=[0,2]</code> and I have set the constraints in the range [0,5] although I would only need them in the range of [0,2] because of the bounds for x(1).
  Now, when I solve it like this I get a solution that doesn't fit all the constraints. But when I delete the unneccessary constraints in the range ]2;5]</p>
  
  <pre><code>function [c,ceq]=cons_Q6(x)
  c=[(0.0-x(1))^4-0.1*(0.0-5)^2
  (0.1-x(1))^4-0.1*(0.1-5)^2
  (0.2-x(1))^4-0.1*(0.2-5)^2
  (0.3-x(1))^4-0.1*(0.3-5)^2
  (0.4-x(1))^4-0.1*(0.4-5)^2
  (0.5-x(1))^4-0.1*(0.5-5)^2
  (0.6-x(1))^4-0.1*(0.6-5)^2
  (0.7-x(1))^4-0.1*(0.7-5)^2
  (0.8-x(1))^4-0.1*(0.8-5)^2
  (0.9-x(1))^4-0.1*(0.9-5)^2
  (1.0-x(1))^4-0.1*(1.0-5)^2
  (1.1-x(1))^4-0.1*(1.1-5)^2
  (1.2-x(1))^4-0.1*(1.2-5)^2
  (1.3-x(1))^4-0.1*(1.3-5)^2
  (1.4-x(1))^4-0.1*(1.4-5)^2
  (1.5-x(1))^4-0.1*(1.5-5)^2
  (1.6-x(1))^4-0.1*(1.6-5)^2
  (1.7-x(1))^4-0.1*(1.7-5)^2
  (1.8-x(1))^4-0.1*(1.8-5)^2
  (1.9-x(1))^4-0.1*(1.9-5)^2
  (2.0-x(1))^4-0.1*(2.0-5)^2
  ];
  ceq=[];
  </code></pre>
  
  <p>then I get the right result. Does anyone know why this happens and why MATLAB does not respect the constraints when I put them up for the whole range [0,5]?</p>