Optimization Where Both Objective and Non-Linear Constraint are Functions of a Function

I am considering an optimization where both the objective and non-linear constraint and functions of a function, such as (excluding some details):
f = @(w,Y) Y*w;
g = @(w,Y) mean(f(w,Y));
h = @(w,Y) var(f(w,Y));
obj_con = @(w,Y) -g(w,Y);
nonl_con = @(w,Y) deal(h(w,Y)-K,[]);
options = optimset('Algorithm','active-set');
out = fmincon(@(x) obj_con(x,Y),x0,[],[],Aeq,beq,lb,ub,@(x) nonl_con(x,Y),options);
I have purposefully made this simpler than what I actually plan to do to get the general point across (in particular, f and h will be more complicated and the optimization may take place with functions other than fmincon).
Using the Matlab profiler, I determined that the function f is called twice at each iteration of the optimization (once for g and once for h).
Is there any way to set up the optimization of the functions so that it is only called once?
One approach I am not interested in is to remove f and make the calculation within g and h. That still does not resolve the issue of having to make such a calculation twice.

 채택된 답변

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기

제품

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by