I think that you missed the step where you call the external function to calculate the nonlinear constraint.
function [c,ceq] = con_EbsOptimize4(para)
global asmInfo app oc model objects Pr Hu Pmeasm Hmeasm Power Powermeasm;
model.Simulate(errors);
Power = oc.CastToComp11(objects.Item('Generator_1'));
Powermeasm = Power.QREAL.Value;
c = Powermeasm-192000;
ceq = [];
end
There are two other things that you might want to keep in mind for this:
- Often, the function that calculates the objective function is the same as the function that calculates the nonlinear constraint. If this is true for your function, consider using the technique in Objective and Nonlinear Constraints in the Same Function.
- If you are using fmincon as your solver, keep in mind the problems in finite differences mentioned in Optimizing a Simulation or Ordinary Differential Equation.
Alan Weiss
MATLAB mathematical toolbox documentation
Best Answer