MATLAB: How to pass a constrain in lsqcurvefit

curve fittingMATLAB

Hi;
For a data set (x, y), I am trying to fit a function , fun(m, x), where there are four independent parameters m1, m2, m3 and m4, with the condtion that m1>m2. Could anyone please suggest how could I pass this condition in the following?
x=xdata;
y=ydata;
fun=(m,x);
lb=[];
m0=[m01; m02; m03]
ub=[];
m=lsqcurvefit(fun, m0, xdata, ydata, lb, ub);
Thank you very much in advance!
Kind regards,
Arun

Best Answer

You cannot impose a strict inequality constraint. In fact, as you have learned based on your other question, sometimes even the bounds can be exceeded by a small amount.
There are simple ways to fix this, for example, using a transformation. Thus you might do something like this in your objective function:
function z = fun(m,x)
mt = m;
mt(2) = m(1) + exp(m(2));
...
Now there are no questions about an inequality. You will need to supply intelligent starting values for the initial m. And when lsqcurvefit returns a result, you must transform it the same way to have the parameters in your desired form. Or, you might use a transformation like
mt(2) = m(1) + m(2)^2;
Alternatively, you can use tools like fmincon to impose an inequality constraint. But remember that fmincon also does not understand a STRICT inequality of the form m(1)>m(2), and it too can exhibit constraint violations on the order of TolCon.