MATLAB: Non linear system of equations with constraints.

fminconlsqnonlinMATLABOptimization Toolbox

I have a system of equations that has 28 state variables that represent physical properties of temperature and pressure, and 28 governing equations based on thermodynamic properties tied to the state variables. The governing equations are not in the form of linear algebra and the state variables are not necessarily in the governing equations, the root of the equation set is the solution to the state. (for clarity, the Jacobian w.r.t. the state variables is full rank) I have attempted to use fsolve, lsqnonlin, and fmincon, with limited success in fsolve and lsqnonlin.
% x = 1 x 28 double, state vector
% f = 28 x 1 double, residual of the system of equations given x
% ub = 1 x 28 double, upper bound of x
% lb = 1 x 28 double, lower bound of x
fsolve has been able to find the root, but seems to not have a way to bound state variables, with either limits or inequalities. This causes it to occationally error out on non-physical values of x(ii) and/or ( x(ii) – x(jj) ) being negative when the governing equations don't allow them to.
lsqnonlin is the most robust I have found so far and is what I would prefer to use. However, I would like to add inequality constraints to ensure solutions are physical. Is it possible to use inequality constraints in the form of A*x <= b to remove the possibility of imaginary numbers? Some of the governing equations include math such as: ( x(3) – x(1) )^0.5, for which I would like to add an inequality relationship such as: x(1) – x(3) <= -1 to remove the possibility of imagainary numbers.
options = optimoptions(@lsqnonlin,'Display','iter','FunValCheck','off','FunctionTolerance', 1e-5, 'StepTolerance', 1e-6);
[x,resnorm,residual,exitflag,output] = lsqnonlin(@SOE_func,x0,lb,ub,options);
fmincon seems to have all of the constraining possibilities that I would like to use, howerver it doesn't seem to be able to solve a system of equations with vector output. Is it possible to use the fmincon sovler with a vector output function?
options = optimoptions(@fmincon,'Display','iter','FunValCheck','off','FunctionTolerance', 1e-6, 'StepTolerance', 1e-6);
[x,~,exitflag,~] = fmincon(@SOE_func,x0,A,b,[],[],lb,ub,[],options);
Thanks

Best Answer

If you would like to apply some inequality constraints using lsqnonlin, you could do this by creating some auxilliary variables. So for example, in your case where you say you are solving for 28 state variables, you could add x(29) = x(3) - x(1), and then apply some bound constraints on x(29). If you want x(3) - x(1) to be non-negative, then set a lower bound for x(29) equal to 0. I'm not sure if you are allowed to set an upper bound of inf, but if not you could put in a sufficiently large number, so that your desired solution would be included.