1 | function [f,err] = fmincon_funn(cbData,nRow,x,njdiff,dXjbase,reserved,inParam) |
---|
2 | |
---|
3 | persistent params hash xevaled oldh F |
---|
4 | if nargin == 7 |
---|
5 | params = inParam; |
---|
6 | hash = randn(1,length(params.linearindicies)); |
---|
7 | oldh = randn(1); |
---|
8 | xevaled = zeros(1,length(params.interfacedata.c)); |
---|
9 | F = []; |
---|
10 | return |
---|
11 | end |
---|
12 | |
---|
13 | x = x(1:length(params.linearindicies)); |
---|
14 | |
---|
15 | if x(:)'*hash(:) ~= oldh |
---|
16 | oldh = x(:)'*hash(:); |
---|
17 | xevaled = zeros(1,length(params.interfacedata.c)); |
---|
18 | xevaled(params.linearindicies) = x; |
---|
19 | |
---|
20 | % Experimental support for arbitrary functions |
---|
21 | if ~isempty(params.interfacedata.evalMap) |
---|
22 | |
---|
23 | pp = params.monomtable(params.nonlinearindicies,:); |
---|
24 | xevaled(params.nonlinearindicies) = prod(repmat(xevaled,length(params.nonlinearindicies),1).^pp,2); |
---|
25 | |
---|
26 | for i = 1:length(params.interfacedata.evalMap) |
---|
27 | arguments = {params.interfacedata.evalMap{i}.fcn,xevaled(params.interfacedata.evalMap{i}.variableIndex)}; |
---|
28 | arguments = {arguments{:},params.interfacedata.evalMap{i}.arg{2:end-1}}; |
---|
29 | xevaled(params.interfacedata.evalVariables(i)) = feval(arguments{:}); |
---|
30 | end |
---|
31 | end |
---|
32 | xevaled(params.nonlinearindicies) = prod(repmat(xevaled,length(params.nonlinearindicies),1).^params.monomtable(params.nonlinearindicies,:),2); |
---|
33 | xevaled = xevaled(:); |
---|
34 | F = -params.F_struc*[1;xevaled]; |
---|
35 | end |
---|
36 | |
---|
37 | if nRow == -1 |
---|
38 | f = params.interfacedata.c'*xevaled+xevaled'*params.interfacedata.Q*xevaled; |
---|
39 | else |
---|
40 | f = F(nRow + 1);%-params.F_struc(nRow + 1,:)*[1;xevaled]; |
---|
41 | end |
---|
42 | err = 0; |
---|