
% This is function nonlconms.m
% Returns nonlconms = Ms-Msmax

% Usage
% A=[];b=[];Aeq=[],beq=[];lb=[];ub=[b];xo=[0.5 8];
% x = fmincon(@funiae,x0,A,b,Aeq,beq,lb,ub,@nonlconms)

function [c,ceq] = mycon(x)
global Kc taui taud numg deng theta 

   w= logspace(-4,4,1000);
   Msmax=1.8;

  numc=conv([1 1/taui],[taud 1]); denc=conv([1 0],[0.0001*taud 1]);
  num=conv(numc,numg); den=conv(denc,deng); gain=Kc;
  

    [Ms,Mspeak]=minbodems(num,den,gain,theta,w);
 % Seems to work best with bound on Msmax as equality constraint:
     c = Ms - Msmax;  
     ceq = Mspeak - Msmax
 

