MATLAB: Discretized/Vector Nonlinear Optimization using fmincon (Optimal Scheduling)

discrete optimizationfminconGlobal Optimization Toolboxnonlinearoptimal schedulingoptimizationOptimization Toolbox

I have a discretized nonlinear optimization problem. I want to find the optimal schedule of a decision variable (X) over 3 sampling instants. I am attempting to use the fmincon function. The objective function (J) for minimization is nonlinear and the only constraints are the upper (ub) and lower bounds (lb) on the decision variable. The solution should be of the form X = [x(1) x(2) x(3)]. Variables T, V_max, & QGg_max are known.
%Known parameters
V_max = 3.15;
Qg_max = 200;
T = [2 4 6];
%Constraints
A = [];
b = [];
Aeq = [];
beq = [];
%Boundary limits
lb = transpose((T/(3.6*Qg_max)).*(ones(1,3)));
ub = V_max*ones(3,1);
%Initial guess
x0 = [1 2 3];
%Optimization
X = fmincon(@myFUN,x0,A,b,Aeq,beq,lb,ub);
The myFUN.m function contains the following code:
function J = myFUN(X)
%Nonlinear objective function
T = [2 4 6];
J = (X.*T.^2) + (X) + ((T.^2)./X) + (T) + (T.*X.^2);
end
But when attempting to run the script, I get the following error:
Error using fmincon (line 619)
Supplied objective function must return a scalar value.
Error in fminconHELP (line 20)
X = fmincon(@myFUN,x0,A,b,Aeq,beq,lb,ub);
I cannot find any help on addressing this issue or an example of using fmincon for discrete nonlinear optimization. So I'm not sure if fmincon can be used for this purpose? In that case, any suggestions on alternative techniques?

Best Answer

As the error message says, the J returned by myFUN is not a scalar, so it is not clear to MATLAB what it means to minimize or maximize it.
In any case, it appears that in your problem each sampling time is independent of the others, so there is no need to approach this as a multi-variable optimization problem. You could just apply fmincon (or even just use fminbnd) to each sampling instant separately:
x0 = [1 2 3];
T=[2,4,6];
for i=1:3
X(i) = fmincon(@(X) (X.*T(i).^2) + (X) + ((T(i).^2)./X) + (T(i)) + (T(i).*X.^2),x0(i),...
[],[],[],[],lb(i),ub(i));
end