-
Notifications
You must be signed in to change notification settings - Fork 2
/
doOptim.m
28 lines (22 loc) · 946 Bytes
/
doOptim.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
function [x,fval] = doOptim(f, x0, A, B, Aeq, Beq, LB, UB, nc, c, nceq, ceq)
% Create an anynomous function to allow the MEX-file to be called by
% the optimizer and be able to pass the function handle to the C function
fWrapper = @(x) evalfunction(f,x);
% do the same for the constraint functions
function [con,coneq] = confun(x)
con = [];
coneq = [];
if ~isempty(c)
con = evalconfunction(c,nc,x);
end
if ~isempty(ceq)
coneq = evalconfunction(ceq,nceq,x);
end
end
% Call fmincon
opts = optimoptions('fmincon', 'Algorithm','active-set');
opts = optimoptions(opts,'Display','iter');
%opts = optimset(opts,'MaxFunEvals',maxfun);
opts = optimoptions(opts,'PlotFcns' ,{@optimplotx @optimplotfval,@optimplotfunccount,@optimplotconstrviolation,@optimplotstepsize});
[x,fval] = fmincon(fWrapper,x0,A,B,Aeq,Beq,LB,UB,@confun,opts);
end