How to solve absolute problem in optimization
9 views (last 30 days)
Show older comments
Hello, i want to solve a quadratic optimization problem (prob.Objective =sum((PgridV).^2);), in constrains i have a one variable where i need to find the absolute value of (Pb1dc). so i introduce a variable called 'K' . where -K<=Pb1dc<=K;
- FYI: i have used absoulte value in the following constrains (prob.Constraints.loadBalanceAC=Pb1==Pb1dc-(0.05*K);)
MATLAB solution showing exactely whati want . its working well.
However, when i want to chage the objective function with little modifcation (prob.Objective =sum((PgridV-M).^2);) where M is a reference signal (mean of Pload), when i run the simulation
absolute vaules (K) are not getting exactley what mean for. its showing random values ( K = absolute ((Pb1dc))
clc
clear all
Pload=[0;1;3;4;2;6;9;10;2;4]; % load
N=10;
M=mean(Pload)+zeros(N,1);
Einit1=0.5; % initial energy
E=zeros(N,1);
Emin1 = 0; % mini energy
Emax1 = 3;
dt=1;
prob = optimproblem;
PgridV = optimvar('PgridV',N,'LowerBound',0,'UpperBound',20); % grid power
Pb1= optimvar('Pb1',N,'LowerBound',-1,'UpperBound',1); % ac power
Pb1dc= optimvar('Pb1dc',N,'LowerBound',-1,'UpperBound',1); % dc power
K=optimvar('K',N,'LowerBound',0);% absolute of (Pb1dc)
EbattV1 = optimvar('EbattV1',N,'LowerBound',Emin1,'UpperBound',Emax1); % energy
prob.ObjectiveSense = 'minimize';
% prob.Objective =sum(K.^2);
%prob.Objective =sum((PgridV).^2);
prob.Objective =sum((PgridV-M).^2);
% 1 constrains
prob.Constraints.energyBalance = optimconstr(N);
prob.Constraints.energyBalance(1) = EbattV1(1) == Einit1-Pb1dc(1)*dt; %Its Ploss is constanat
prob.Constraints.energyBalance(2:N-1) = EbattV1(2:N-1) == EbattV1(1:N-2)-Pb1dc(2:N-1)*dt;
prob.Constraints.energyBalance(N) = EbattV1(N) ==Einit1;
% K constrain for Pb1dc modulous
prob.Constraints.kbalance1=optimconstr(N);
prob.Constraints.kbalance1(1:N)=-K(1:N)<=Pb1dc(1:N);
prob.Constraints.kbalance2=optimconstr(N);
prob.Constraints.kbalance2(1:N)=Pb1dc(1:N)<=K(1:N);
% load Balance
prob.Constraints.loadBalance=PgridV+Pb1==Pload;
% loss term
prob.Constraints.loadBalanceAC=Pb1==Pb1dc-(0.05*K);
options = optimoptions(prob.optimoptions,'Display','final');
% options = optimoptions(prob.optimoptions,'Algorithm','interior-point');
[values,fval,exitflag] = solve(prob,'Options',options)
% Parse optmization results
if exitflag <= 0
PgridV = zeros(N,1);
Pb1 = zeros(N,1);
Pb1dc = zeros(N,1);
EbattV1 = zeros(N,1);
K = zeros(N,1);
else
PgridV = values.PgridV ;
Pb1 = values.Pb1;
Pb1dc = values.Pb1dc
EbattV1 = values.EbattV1;
K = values.K
end
.
4 Comments
Answers (1)
See Also
Categories
Find more on Linear Least Squares in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
