fmincon is returning some garbage values in the final output

3 views (last 30 days)
clc
[load_data,txt,raw] = xlsread('Load profile data.xlsx');
schedule=zeros(24,9);
schedule_final=zeros(24,5);
for i=1:24
f=[2 1 1 2 0 0 0 0];
intcon=[5,6,7,8];
A=[ 1 0 0 0 -1080 0 0 0;
-1 0 0 0 360 0 0 0;
0 1 0 0 0 -540 0 0;
0 -1 0 0 0 180 0 0;
0 0 1 0 0 0 -540 0;
0 0 -1 0 0 0 180 0;
0 0 0 1 0 0 0 -1080;
0 0 0 -1 0 0 0 360];
b=[0 0 0 0 0 0 0 0];
Aeq=[1 1 1 1 0 0 0 0];
beq=[load_data(i,2)];
lb=[0 0 0 0 0 0 0 0];
ub=[1080 540 540 1080 1 1 1 1];
X=intlinprog(f,intcon,A,b,Aeq,beq,lb,ub);
schedule(i,:)=[load_data(i,2) X'];
end
disp(schedule);
for i=1:24
objective=@(p) 787.16-1.3217*(schedule(i,6)*p(1)+schedule(i,9)*p(4))-0.9312*(schedule(i,7)*p(2)+schedule(i,8)*p(3))+0.0092*((schedule(i,6)*p(1))^2+(schedule(i,9)*p(4))^2)+0.0062*((schedule(i,7)*p(2))^2+(schedule(i,8)*p(3))^2);
p0=[0,0,0,0];
%disp(['initial objective: ' num2str(objective(p0))])
A=[];
b=[];
Aeq=[schedule(i,6:9)];
beq=[load_data(i,2)];
lb=[0,0,0,0];
ub=[1200,600,600,1200];
nonlincon=@nlconProj;
[p,fval,ef,output]=fmincon(objective,p0,A,b,Aeq,beq,lb,ub,nonlincon);
schedule_final(i,:)=[p load_data(i,2)];
end
disp(' Gen_1 Gen_2 Gen_3 Gen_4 Total_Load')
disp(schedule_final);
disp(schedule);
%%nlcon for nonlinear constraints (my problem doesnt have any non linear constraints
function [c,ceq]=nlcon(x)
ceq=[];
c=[];
end
above is the code( am attaching .m file and required excel file for reference.)
bsically am trying to schedule four generators as per thier SFOC curves( objective is it minimise specific fuel oil consumption)
when i run the optimisation
equality constraint says "P2+P3=773.26" and my objective function contains F(P1),F(P2),F(P3),F(P4)
the result is (in first iteration)
P1 P2 P3 P4 Total Load
1.6548 386.63 386.63 1.6548 773.26
wherein the result should be
P1 P2 P3 P4 Total Load
0 386.63 386.63 0 773.26
can someone clarify why these values are being shown instead of zero (1.6548 ) in the result.?
will be pleased to share additional info if desired.

Answers (1)

Alan Weiss
Alan Weiss on 6 Oct 2021
When I run your script I get the same results as you, so thank you for including all the relevant information.
Note that your constraint Aeq*x = beq does NOT preclude p(1) and p(4) from being nonzero. In fact, those variables can have any value; they don't affect the linear equality.
I then tried the following experiment:
% Obtain the result for i = 1
i = 1;
objective=@(p) 787.16-1.3217*(schedule(i,6)*p(1)+schedule(i,9)*p(4))-0.9312*(schedule(i,7)*p(2)+schedule(i,8)*p(3))+0.0092*((schedule(i,6)*p(1))^2+(schedule(i,9)*p(4))^2)+0.0062*((schedule(i,7)*p(2))^2+(schedule(i,8)*p(3))^2);
p0=[0,0,0,0];
A=[];
b=[];
Aeq=[schedule(i,6:9)];
beq=[load_data(i,2)];
lb=[0,0,0,0];
ub=[1200,600,600,1200];
nonlincon=@nlconProj;
[p,fval,ef,output]=fmincon(objective,p0,A,b,Aeq,beq,lb,ub,nonlincon);
schedule_final(i,:)=[p load_data(i,2)];
objzero = objective([0,p(2),p(3),0]) % Objective with 0 for p(1) and p(4)
fval - objzero
I get zero as the value of fval - objzero. This means that the objective function value is the same for these values as for the final value. In other words, fmincon sees no difference in the objective function, so there is no reason to prefer one of these final values over another.
If you want fmincon to return zero values, then make p(1) and p(4) part of the objective, such as
objective = @(p) (your expression) + p(1) + p(4);
I found that adding (p(1) + p(4))*1e-3 did not give me exactly 0 for p(1) and p(4). So I think that your objective might be somewhat sensitive to the values. And that is why fmincon returns nonzero values.
Alan Weiss
MATLAB mathematical toolbox documentation

Products


Release

R2020b

Community Treasure Hunt

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

Start Hunting!