MATLAB: Fmincon nonlinear constrain problem set-up

fminconoptimization

One of my initial conditions is leaving me scratching my head. Since R & C are defined by summing functions (R will have w components and C will have d components), it may be simpliest to represent R & C as functions. Since there is a function f embedded in R, I run in to problems. I can see how to establish the A,b,Aeq and beq inputs, but I have no clue how to represent the nonlinear constraint of f and pass it in to R. Any help would be much appreciated.
P=R-C; % Objective Function
-P <= 0;
R= sum(U*f(sum(sqrt(((Xb+X)-Xw)^2)));
C= sum(Md*(X-Xb)+B);
f=@d h*exp(1/d);

Best Answer

Something like the following, perhaps?
Pfun=@(X) objectiveFull(X, Xb,Xw, U Md,B,h);
nonlcon=@(X) nonlconFull(X,Pfun);
Xopt = fmincon(Pfun,X0, A,b,Aeq,beq,[],[],nonlcon)
function P=objectiveFull(X,Xb,Xw, U Md,B,h)
f=@(d) h*exp(1/d);
R= sum(U*f( norm(X-(Xw-Sb) ) ) );
C= sum(Md*(X-Xb)+B);
P=R-C;
function [c,ceq]=nonlconFull(X,Pfun)
ceq=[];
c=-Pfun(X);