title: Functionally constrained optimization using fmincon (in Matlab)?
body: <p>I want to set a constraint for every x value, 0&lt;=f(x,vctr)&lt;=100. The result is:</p>
  
  <blockquote>
    <p>??? Undefined function or variable 'x' due to functional constraint "cnstrnt". </p>
  </blockquote>
  
  <p>Although it is a variable, <code>fmincon</code> asks for a value of <code>x</code> in <code>cnstrnt</code>. <code>x</code> represents multiple variables. <code>b</code>, <code>k</code>, and <code>vctr</code> (vector of constants) are constants. What is the correct way of coding the constraint?</p>
  
  <pre><code>function [ h ] = f(x,vctr)
  
  g=@(x) (vctr(1,6).*x.^5+vctr(1,5).*x.^4+vctr(1,4).*x.^3+ ...
  vctr(1,3).*x.^2+vctr(1,2).*x.^1+vctr(1,1));
  h=fzero( @(x)(g(x)-y),0);
  end
  
  function [ cc,ceq ] = cnstrnt(x,b,vctr)
  
  for k=1:length(b)*2
  
         cc(k)=f(x(k),vctr)-100;
         cc(k+1)=-f(x(k),vctr);
  end
  
  ceq=[];
  
  end
  
  
  [result,FVAL,EXITFLAG,OUTPUT,LAMBDA,GRAD,HESSIAN]= fmincon(@(x)obj(x,b,c,L,vctr) ,x0,A,B,Aeq,beq,[],ub,cnstrnt(x,b,vctr),opts);
  
  ??? Undefined function or variable 'x'.
  </code></pre>